Cryptic C (enum as boolean type)

Dick Dunn rcd at opus.UUCP
Fri Aug 30 15:02:04 AEST 1985


> Instead of using #defines for the boolean values, I
> would rather see enumerated data types used.  In general,
> C programmers seem to prefer #defines to defining a data
> type that can be checked during compilation.
> 
> 	typedef enum { False , True } Boolean;

Whether this works depends on your compiler's view of enums.  If it treats
enums as a slight variant on integers (which to my tastes is pretty
sloppy), you're OK.  However, if it uses the very restricted view which
doesn't allow arithmetic on enums, the above definition will prevent the
"usual" logical operators !, &, ^, and | from working with objects of type
Boolean.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Relax...don't worry...have a homebrew.



More information about the Comp.lang.c mailing list