Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Has TRUE always had a non-zero value?

Tags:

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?

like image 208
DMKing Avatar asked Sep 19 '08 18:09

DMKing


People also ask

Is a non-zero value true?

In Python any non-zero integer value is true; zero is false.

Is any non-zero value true in C++?

For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true. C++ is backwards compatible, so the C-style logic still works in C++. ( "true" is stored as 1, "false" as 0. )

Is nonzero true in C?

Boolean Variables and Data Type ( or lack thereof in C ) For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.

Is it true one or zero?

Like in C, the integers 0 (false) and 1 (true—in fact any nonzero integer) are used.


2 Answers

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.

like image 91
webmat Avatar answered Oct 15 '22 04:10

webmat


It might be in reference to a result code of 0 which in most cases after a process has run, a result code of 0 meant, "Hey, everything worked fine, no problems here."

like image 40
stephenbayer Avatar answered Oct 15 '22 04:10

stephenbayer