Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!bellcore!faline!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Enumerated types Message-ID: <9297@alice.UUCP> Date: 4 May 89 13:41:07 GMT References: <1152@unh.UUCP> Distribution: usa Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 34 In article <1152@unh.UUCP>, al712@unh.UUCP (Anthony Lapadula) writes: > Are you allowed to 'forward reference' enumerated types? In other > words, is this legal? > enum a b; /* 'enum a' is not yet defined */ > Does 'b' end up as an int, or is this an error? It's an error, both in C++ and ANSI C. > Also, how about this? > char *ptr; > enum a { b }; /* 'b' has value 0 in expressions, right? */ Right. > if (ptr == b) /* Same as (ptr == NULL) ? */ > foo(); Yes, if NULL==0, by virtue of the fact that b is 0. However, the following is illegal: enum a1 {b1, c1}; if (ptr == c1) foo(); because the only integral value that may be meaningfully compared to a pointer is 0. -- --Andrew Koenig ark@europa.att.com