enums
D. Hugh Redelmeier
hugh at dgp.toronto.edu
Mon Jul 25 07:47:14 AEST 1988
In article <1608 at dataio.Data-IO.COM> bright at Data-IO.COM (Walter Bright) writes:
>From reading the grammar for enums in the Ansi spec, it seems that the
>following is not allowed:
>
> enum abc { }; /* empty member list */
> enum def { b, }; /* trailing comma */
>
>Many compilers accept this, and I've run across code that uses it. Any
>thoughts? Is this an oversight in the spec?
I submitted a comment on the trailing comma during the first public
review period. So it isn't an oversight, but I do think that it is
a mistake. I am not sure how I feel about empty enums (perhaps a
good definition for void might be: "typedef void enum {};" :-).
Here is my comment:
Section 3.5.2.3, page 54, line 17 [of the then-current draft]
I think that an enumerator-list should be optionally terminated by a
comma. This is analogous to the way an initializer is optionally
terminated by a comma (3.5.6 61 at 21). The benefits are similar (a
terminator is less error-prone than a separator (consider Pascal's
semicolon)).
This is currently legal in the two compilers I use (the Ritchie
compiler (the original implementation of enum, so it should carry
some weight), and System V VAX UNIX PCC). I do use the feature.
Hugh Redelmeier
{utcsri, utzoo, yunexus, hcr}!redvax!hugh
In desperation: hugh at csri.toronto.edu
+1 416 482 8253
More information about the Comp.std.c
mailing list