Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Enumerated types Message-ID: <17292@mimsy.UUCP> Date: 4 May 89 05:56:50 GMT References: <1152@unh.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 27 In article <1152@unh.UUCP> al712@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 . -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris