Enumerated types

Chris Torek chris at mimsy.UUCP
Thu May 4 15:56:50 AEST 1989


In article <1152 at unh.UUCP> al712 at unh.UUCP (Anthony Lapadula) writes:
>Are you allowed to 'forward reference' enumerated types?

No.

>Also, how about this?
>
>	char *ptr;
>	enum a { b };		/* 'b' has value 0 in expressions, right? */
>
>	if (ptr == b)		/* Same as (ptr == NULL) ? */
>		foo();

Modulo some waffling about what constitutes an `integer constant zero',
all C compilers should accept this.  (I would not object to a warning,
myself.)  The way one obtains a nil pointer of type T is to write an
expression which demands or produces a pointer of type T but is in fact
an integer constant zero.  To me, `the integer constant zero' means
`any constant expression whose type is one of the integral types and
whose value is zero'.  According to the pANS, the type of an
enumeration member is integral (I forget whether it is |int| or merely
one of |signed char|, |short|, |int|, or |long|, but it is not unsigned
... at least, I think I would remember if it were allowed to be
unsigned).  So we have <pointer> <comparison-op> <integer-zero>.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list