What should be added to C (booleans)

Barry Margolin barmar at mit-eddie.MIT.EDU
Wed Jun 4 16:13:14 AEST 1986


In article <167 at zaiaz32.UUCP> rlb at zaiaz32.UUCP writes:
>> 
>> provided that the two expressions evaluate to whatever a boolean int is
>> locally (1 or -1).  {BTW I usually use set_me_true = (1 == 1)}
>> 
>
>This worries me, much the same as when I see someone code:
>
>	#define	FALSE	0
>	#define	TRUE	!FALSE
>
>Makes me think that the person writing may really not know that a C
>"boolean" expression (expression formed with the logical/relational operators)
>is *defined* to be either 1 or 0.

I think your worries are unfounded.  The difference between (1 == 1) and
1 is that the former indicates to human readers of the code that the
expression is being used for its truth value.  In the statement
	var = 1;
the reader is likely to assume that var is going to be used
arithmetically.

To calm your fears about the #define's, let me try a little satirical
analogy:
---------
This bothers me, much the same as when I see someone code
	file = fopen (...);

Makes me thing that the person writing may really not know that the
standard I/O library function "fopen" is *defined* to return a file.
----------

The point of the analogy is that there is nothing wrong with using
menmonic names for things.  While it may be true that C defines 0 and 1
to be falsity and truth, it doesn't hurt to use macros to say what you
really mean.
-- 
    Barry Margolin
    ARPA: barmar at MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar



More information about the Comp.lang.c mailing list