有真始终有一个非零值? [英] Has TRUE always had a non-zero value?

查看:127
本文介绍了有真始终有一个非零值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个同事说认为TRUE曾经被定义为0,所有其他值都是假的。我可以发誓,每一个我曾经使用过,如果你甚至可以得到一个布尔值语言,对于FALSE值为0。难道真曾经是0?如果是这样,我们什么时候切换?

I have a co-worker that maintains that TRUE used to be defined as 0 and all other values were FALSE. I could swear that every language I've worked with, if you could even get a value for a boolean, that the value for FALSE is 0. Did TRUE used to be 0? If so, when did we switch?

推荐答案

0 /非0的事情你的同事是感到困惑所指的可能是,当人们使用数值作为返回值表示成功,不是真理(即在bash脚本和一些风格的C / C ++)的。

The 0 / non-0 thing your coworker is confused about is probably referring to when people use numeric values as return value indicating success, not truth (i.e. in bash scripts and some styles of C/C++).

使用0 =成功允许更大precision在指定失败的原因(例如,1 =丢失的文件,2 =缺肢,等等)。

Using 0 = success allows for a much greater precision in specifying causes of failure (e.g. 1 = missing file, 2 = missing limb, and so on).

作为一个方面说明:在Ruby中,只有虚假的值是零和假。 0是真实的,但不相对于其他的数字。 0为真,因为它的对象0的一个实例。

As a side note: in Ruby, the only false values are nil and false. 0 is true, but not as opposed to other numbers. 0 is true because it's an instance of the object 0.

这篇关于有真始终有一个非零值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆