Definition of boolean type
Alastair Dallas
awd at dbase.UUCP
Sat Feb 4 08:03:03 AEST 1989
We've discussed the proper definition of NULL a great deal, and I understand
that the ANSI standard now specifies it. But what about a boolean type?
Please excuse me if the standard discusses this as well, but I can think
of several ways to handle booleans (and I've worked on code that used all
three):
1. typedef short bool;
2. typedef char bool;
3. typedef enum {FALSE=0, TRUE=1} bool;
I like the last one, but it requires a compiler that doesn't complain about
constructs like:
bool flag = TRUE;
if (flag)
...
Some compilers I've run into want that to be either:
if ((short) flag)
or
if (flag == TRUE)
While this means more typing*, I'm inclined to forgo the convenience of
if (flag) in favor of the self-documentation of the explicit if (flag==TRUE).
I'm curious what the net thinks. Are there any other problems with using
an enum? While we're at it, I'd like to hear opinions pro and con on the
use of all upper case to identify typedefs--bool vs. BOOL vs. Bool.
/alastair/
*No pun intended.
More information about the Comp.lang.c
mailing list