TRUE and FALSE

David T. Sandberg dts at quad.sialis.mn.org
Sat Sep 1 21:34:17 AEST 1990


In article <664 at csource.oz.au> david at csource.oz.au writes:
>Shouldn't
>
> # define FALSE 0
> # define TRUE  (!FALSE)
> 
>_always_ work?

Sorry, this is no different than defining TRUE as 1... (!FALSE) is
(!0) is (1), after all.

My two cents: I define FALSE as 0 and TRUE as 1 on a regular basis,
but only use them to make assignments to flag variables more self-
documenting.  I seldom use the defines for the conditional tests of
those variables, and _never_ use them to test the zero or nonzero
condition of any function or expression which doesn't explicitly use
those same defines in yielding it's result (that means no standard
library functions or macros, for starters).  When I do need to save
the result of such things in a variable being used as a boolean, I
do so using the longer (but safer) method:

	int gotdigit = isdigit(c) ? TRUE : FALSE;

(This could be made into a BoolValue() macro if one wished to do so.
I haven't.)

It seems to me that these defines can be quite helpful and safe if
the programmer maintains some level of discipline and restraint in
deciding where it is appropriate to use them.  In fact, at the
restricted level in which they appear in my code, TRUE could be
defined as any nonzero value without adversely affecting it's
functionality.  If changing TRUE's value would break any given
expression, then that expression is one which in my opinion should
have been considered to be out of the scope of these defines in the
first place.

-- 
 \\                                 \   David Sandberg, consultant   \\
 //         "Small hats!"           /   Richfield MN                 //
 \\                                 \   dts at quad.sialis.mn.org       \\



More information about the Comp.lang.c mailing list