Enumerated types

Andrew Koenig ark at alice.UUCP
Thu May 4 23:41:07 AEST 1989


In article <1152 at unh.UUCP>, al712 at 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 at europa.att.com



More information about the Comp.lang.c mailing list