enums

Ray Butterworth rbutterworth at watmath.waterloo.edu
Fri Jul 29 00:16:46 AEST 1988


In article <5514 at haddock.ISC.COM>, karl at haddock.ISC.COM (Karl Heuer) writes:
> In article <1608 at dataio.Data-IO.COM> bright at Data-IO.COM (Walter Bright) writes:
> >[ANSI C seems not to allow:]
> >	enum abc { };		/* empty member list	*/
> >	enum def { b, };	/* trailing comma	*/
> 
> I can see why one might want to allow the trailing comma, but what good is an
> enum with no values?  I think this is almost in the same category as
> zero-sized objects.  (I.e., the rule that allows small-valued enums to be
> stored in a char could be logically extended to allow non-valued enums to be
> stored in a zero-size type.)

Exactly.
It's been pointed out before that if enums with no values were allowed,
one could simply use:
#typedef enum {} void;
and not need void as part of the language.

It would then be obvious why any other pointer could be cast to a (void*)
since obviously (void*) needs the finest resolution,
and it would be obvious why trying to subscript a void* would be
useless (vs[7] would have a size of 7*sizeof(void)  which is 7*0),
and why a function returning void doesn't really return anything,
or rather that what it returns is something that was already known
before the function was called and one can't do anything with it anyway.



More information about the Comp.std.c mailing list