[computer-go] Orego Episode 6 posted

Eric Boesch ericboesch at hotmail.com
Sat Aug 26 12:50:51 PDT 2006


C Boolean expressions (==, <, !=, &&, et cetera) output 0 (false) or 1 
(true). No other result is possible (unless you write a program with 
undefined behavior). See the C standard ISO 9899:1999 6.5.9 for example, or 
take this quote from what I think is literally the next best thing to the 
standard, namely the C FAQ (a more reliable document than the great majority 
of programming guidebooks):

comp.lang.c FAQ list · Question 9.2

Q: Isn't #defining TRUE to be 1 dangerous, since any nonzero value is 
considered ``true'' in C? What if a built-in logical or relational operator 
``returns'' something other than 1?

A: It is true (sic) that any nonzero value is considered true in C, but this 
applies only ``on input'', i.e. where a Boolean value is expected. When a 
Boolean value is generated by a built-in operator such as ==, !=, and <=, it 
is guaranteed to be 1 or 0. Therefore, the test

	if((a == b) == TRUE)

would work as expected (as long as TRUE is 1), but it is obviously silly.



I'd dig up the C++ standard also, but true is a builtin keyword in C++ and 
it would be just idiotic if true expressions did not equal true, which 
equals ((bool) 1).




More information about the computer-go mailing list