Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!utgpu!water!watmath!jyegiguere
From: jyegiguere@watmath.UUCP
Newsgroups: comp.lang.c
Subject: Defining TRUE and FALSE
Message-ID: <13851@watmath.UUCP>
Date: Wed, 8-Jul-87 13:08:46 EDT
Article-I.D.: watmath.13851
Posted: Wed Jul  8 13:08:46 1987
Date-Received: Fri, 10-Jul-87 02:45:19 EDT
Reply-To: jyegiguere@watmath.waterloo.edu (Eric Giguere)
Organization: U. of Waterloo, Ontario
Lines: 57
Keywords: boolean, true, false
Summary: standard definitions for boolean  values


There's been a debate raging on the nets lately about what is a
"proper" definition for the TRUE and FALSE macros in C. 
The way we define these at the Computer Systems Group here at
UW (which we include in the  file for Waterloo C)
is:

          #define TRUE   ( 0 == 0 )
          #define FALSE  ( 1 == 0 )

The point here is that instead of letting the program arbitrarily
decide what TRUE and FALSE should be, we let the compiler decide,
which adds to the portability.  Since the above definitions are simple
constant expressions, any compiler worth its salt should recognize
them as such and not generate any less efficient code than a direct
comparison to a straight integer constant.

In actual effect, the definition for FALSE above could just as well
be replaced with

          #define FALSE   0

since in C only non-zero values are considered to be 'true' in
logical expressions.  People have noted that some programmers code
things like

          if( my_func() == TRUE )

when my_func() returns a non-zero value that isn't necessarily the 
same as TRUE.  In such cases why not code

          if( my_func() != FALSE )

since anyone who declares FALSE to be anything other than zero is
going to run into a few problems.  I still prefer the TRUE form
if I know for SURE that the function will return either TRUE or FALSE
as defined in .  In any case, I find both forms above more
readable than 

          if( my_func() )

or

          if( !my_func() )

This, however, is due to personal preferences and I don't believe 
that one form is right and the other wrong (as long as they both
do the exact same thing!)

-----------------------------

Eric Giguere
Computer Systems Group, UW
 
Disclaimer:  The above views are NOT intended to represent those of
either the Computer Systems Group or the University of Waterloo.