Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!mcvax!enea!chalmers!bergsten From: bergsten@chalmers.UUCP (Per Bergsten) Newsgroups: comp.lang.c Subject: Re: Enum vs Define ===> BUG REPORT Message-ID: <1834@chalmers.UUCP> Date: Sun, 2-Aug-87 21:01:59 EDT Article-I.D.: chalmers.1834 Posted: Sun Aug 2 21:01:59 1987 Date-Received: Wed, 5-Aug-87 05:02:06 EDT References: <19913@ucbvax.BERKELEY.EDU> <447@umbc3.UMD.EDU> <24622@sun.uucp> Reply-To: bergsten@chalmers.UUCP (Per Bergsten) Organization: Dept. of CS, Chalmers, Sweden Lines: 45 (Maybe this message should go to comp.bugs.something or sunspots). The recent discussion about relative merits of the "enum" type made me remember an obscure bug in PCC I discovered some time ago and (almost) forgot. The following example should NOT be construed as a discredit to the idea of enum. I am prepared to accept all the help the language/compiler can give; I regard "enum" types as a small but not useless tool. However, current implementations are lacking in quality. ------------------------------------------------------------------------------- Consider: typedef enum { a=0, b=1, c=2 } t1; mine() { printf("mine: a=%d, b=%d, c=%d\n", a, b, c); } main() { typedef enum { b=0, c=1, d=2 } t2; mine(); printf("main: b=%d, c=%d, d=%d\n", b, c, d); exit(0); } On VAX/BSD 4.2 and on SUN-3/SunOs3.2 I obtain the following output: mine: a=0, b=1, c=2 main: b=1, c=2, d=2 ^ ^ In my opinion this is wrong. I do confess I don't have access to a C-standard document so my understanding of C is largely based on K&R and some 8 years of practise, nevertheless I don't think that the compiler behaves correctly. At the very least I would expect an error message if this is an illegal program. Incidentally: lint (in verbose mode) only prints a warning that "b" and "c" are redefined. ------------------------------------------------------------------------------- Per Bergsten bergsten@chalmers.se ........!mcvax!enea!chalmers!bergsten a.k.a perb%holtec.uucp@chalmers