[comp.lang.c] TRUE, FALSE and writing readable code...

C03601DM%WUVMD.BITNET@wiscvm.wisc.EDU (Derek Morgan) (07/27/87)

I'm a C and a net novice, so please keep your flames low. Anyway, I've been
reading about the TRUE/FALSE controversy, and I'm confused. With a background
in BASIC, FORTRAN, and ALGOL (yes, D. Goodenough, there's somebody else!), I
was used to boolean operations. To tailor *my* C environment, I naively used
#define TRUE 1
#define FALSE 0
in one of my header files. This makes it very easy for me to understand the
assignments to variables when they are made (e.g., stasis = TRUE;). In this
program (system),"stasis" functions as a boolean variable.  When testing the
value of stasis, I use the form "if (stasis) or if (!stasis)". What pitfalls
have I left myself open to by using something which I consider mnemonic?

Derek Morgan (What am I doing in this language?  It's efficient.)
BITNET: C03601DM@WUVMD

gwyn@brl-smoke.ARPA (Doug Gwyn ) (07/28/87)

In article <8507@brl-adm.ARPA> C03601DM%WUVMD.BITNET@wiscvm.wisc.EDU (Derek Morgan) writes:
>What pitfalls
>have I left myself open to by using something which I consider mnemonic?

So long as you never write
	if ( whatever == TRUE )
there is no technical problem with using your mnemonics.
The only possible problem otherwise is that, because they're not
a standard part of the language, a reader of your code has to do
more work to understand the mnemonics.  However, these particular
ones are nearly universal and are unlikely to confuse anyone.

rwm@osupyr.UUCP (Robert Manson) (07/29/87)

I'm a real novice to the net, but a somewhat experienced C programmer. I've
never had any problems with true/false values (maybe due to lack of
experience?, but it seems to me that any problems could be solved with:
	#define true(X) (X!=0)
or however one would want to define "truth".I'm not sure exactly what the
original argument was, but it seems to me that a test like:
	f(x)==TRUE
is always going to be dependent on the function, and I would say a very
bad practice (not to say somewhat machine dependent). The above #define
has the advantage that it could be varied as needed from machine to
machine.
						Bob Manson
Disclaimer: I quite possibly have no idea what anyone else is talking
about, including me.