Path: utzoo!utgpu!watmath!clyde!att!rutgers!gatech!purdue!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!hp4nl!botter!star.cs.vu.nl!leendert@cs.vu.nl From: leendert@cs.vu.nl (Leendert van Doorn) Newsgroups: comp.std.c Subject: Re: trailing comma inside enum...bug or feature? Keywords: ANSI C, enumeration tags Message-ID: <1781@zell.cs.vu.nl> Date: 8 Dec 88 13:30:48 GMT References: <2174@vedge.UUCP> Sender: leendert@cs.vu.nl Reply-To: leendert@cs.vu.nl ()Leendert van Doorn Organization: VU Informatica, Amsterdam Lines: 51 In article <2174@vedge.UUCP> lai@vedge.UUC writes: >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? You're probably using PCC which has the following grammar for enums: enum_dcl: enum_head '{' moe_list optcomma '}' | ENUM NAME ; enum_head: ENUM |ENUM NAME ; moe_list: moe | moe_list CM moe ; moe : NAME | NAME '=' con_expr ; optcomma: /* epsilon */ | ',' ; This feature is only useful when automaticly generating enum tags (e.g. by macros; in this case it's very hard to remove the last trailing comma). Any further usage is unknown to me. I think that the designers (was this an invention of Steve Johnson?) wanted to conform to the initialization syntax. >Is this a bug or feature? An undocumented feature. >Should ANSI compilers allow this? No, they shouldn't. However in the ANSI C compiler I wrote, the trailing comma is accepted but flagged by a warning message. This makes it possible to compile things like gcc and X11. -- Leendert P. van DoornVrije Universiteit / Dept. of Maths. & Comp. Sc. De Boelelaan 1081 1081 HV Amsterdam / The Netherlands tel. +31 20 548 5302