Has TRUE always had a non-zero value?

前端 未结 22 823
予麋鹿
予麋鹿 2020-12-31 01:38

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

22条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-31 01:48

    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++).

    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).

    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.

提交回复
热议问题