TRUE 是否始终具有非零值? [英] Has TRUE always had a non-zero value?
问题描述
我有一位同事坚持认为 TRUE 曾经被定义为 0,而所有其他值都是 FALSE.我可以发誓我使用过的每一种语言,如果你甚至可以得到一个布尔值,那么 FALSE 的值是 0.TRUE 曾经是 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/non-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 = 成功可以更精确地指定失败原因(例如 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 中,唯一的 false 值是 nil 和 false.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.
这篇关于TRUE 是否始终具有非零值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!