Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!mtuxo!mtune!akguc!akgua!gatech!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.lang.c Subject: Re: Boolean datatypes Message-ID: <2022@umcp-cs.UUCP> Date: Sun, 15-Jun-86 15:12:52 EDT Article-I.D.: umcp-cs.2022 Posted: Sun Jun 15 15:12:52 1986 Date-Received: Tue, 17-Jun-86 11:07:05 EDT References: <210@pyuxv.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 35 In article <210@pyuxv.UUCP> cim2@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@umcp-cs ARPA: chris@mimsy.umd.edu