Boolean datatypes
Robert L. Fair
cim2 at pyuxv.UUCP
Fri Jun 13 09:22:24 AEST 1986
At the risk of being flamed, I've been using enums for a proper boolean
datatype for years:
typedef enum { false=0,true } bool;
bool flag=false;
if(!flag)
...
This has _lots_ of advantages over the usual #defines - especially with
a decent compiler which will barf on constructs like:
flag=10; /* correct syntax error,10 is neither true nor false */
or
enum states {activate,inactive,comatose} state;
flag=state; /* correct syntax error - a state isn't a boolean */
Many current C compilers now implement enums properly (i.e. each enumeration
is a distinct type) yet they are hardly ever used. Any comments why not ?
Rob Fair
Bell Communications Research
ihnp4!pyuxv!cim2
More information about the Comp.lang.c
mailing list