lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 02.07.2013 01:20 schröbte Sean Conner:
   Actually, I've seen plenty of C code improperly define the value for true.
In C, a value of 0 is considered false, and *anything but 0* is considered
true, so (in my not so humble opinion) the best definition of TRUE and FALSE
would be:

#define FALSE	0
#define TRUE	!FALSE

But I've seen code that does:

#define TRUE	1
#define FALSE	0

which mostly works, but can fail in some obscure cases.

For a conforming ISO C90+ compiler both cases are equivalent:

3.3.3.3 Unary arithmetic operators
[...]
The result of the logical negation operator ! is 0 if the value of
its operand compares unequal to 0, 1 if the value of its operand
compares equal to 0.  The result has type int .


Philipp