Boolean datatypes

chris at umcp-cs.UUCP chris at umcp-cs.UUCP
Mon Jun 16 05:12:52 AEST 1986


In article <210 at pyuxv.UUCP> cim2 at pyuxv.UUCP (Robert L. Fair) writes:
>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;
>
>... 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 */

Neither of these is syntactically incorrect; a compiler that gives
a syntax error is printing the wrong message.  Rather, these are
semantically incompatible (though this depends on your semantics).

>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 ?

PCC does about half the job, mostly because it gets stickier as you
go along.  For example, should printf() be able to print enumerations?
If so, should it print them as integers or as strings?  Should scanf()
handle enumerations?  Where is the line between the integer/enumeration
split?

The latest-I-have-seen ANSI X3J11 draft has `enum's defined simply
as aliases for integers, which means one might as well just use
`#define'. . . .
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list