trailing comma inside enum...bug or feature?
David Lai
lai at vedge.UUCP
Wed Dec 7 04:42:54 AEST 1988
Why does something like:
/* taken straight out of X11/Intrinsic.h, from Xwindows from MIT */
typedef enum {
XtGeometryYes, /* Request accepted. */
XtGeometryNo, /* Request denied. */
XtGeometryAlmost, /* Request denied, but willing to take replyBox. */
XtGeometryDone, /* Request accepted and done. */
} XtGeometryResult;
/* note trailing comma after XtGeometryDone */
elicit no complaints from any of the C compilers I use? I have a couple of
theories:
1) This is an archaic remnant from bygone days when enums syntax
allowed trailing commas
2) This is a bug in the original C compiler, from which all other C
compilers were ported from. I suspect this because of the
vast number of systems that X has been ported to using the
above file.
3) The books are wrong, the syntax should really read:
enum_type_def: enum opt_enum_tag { enum_def_list }
| enum opt_enum_tag { enum_def_list , }
4) The C compiler writers were forced to stray from the specification
because of files like the above.
5) Perhaps I'm misinformed, and a trailing comma has some sort of
special hidden meaning...
Is this a bug or feature? Should ANSI compilers allow this? I only caught
this because I'm designing a C parser directly from the specifications.
I hope somebody in the X consortium sees this (and corrects it for the next
release).
The C standard (and every book on C I've seen, including those from
AT&T) says the syntax of an enum declaration is:
enum_type_def: enum opt_enum_tag { enum_def_list }
enum_def_list: enum_const_def
| enum_def_list , enum_const_def
enum_const_def: enum_constant
| enum_constant = expression
--
"What is a DJ if he can't scratch?" - Uncle Jamms Army
The views expressed are those of the author, and not of Visual Edge, nor Usenet.
David Lai (vedge!lai at larry.mcrcim.mcgill.edu || ...watmath!onfcanim!vedge!lai)
More information about the Comp.std.c
mailing list