[comp.lang.c] enum, no trailing comma?

rtm@christmas.UUCP (Richard Minner) (08/18/90)

Is it just my eyes or does:

(From December 7, 1988 DRAFT)
3.5.2.2 Enumeration specifiers

Syntax
	<enum-specifier>:
		enum <identifier>_opt { <enumerator-list> }
		enum <identifier>

	<enumerator-list>:
		<enumerator>
		<enumerator-list>, <enumerator>

	<enumerator>:
		<enumeration-constant>
		<enumeration-constant> = <constant-expression>
		
mean that a trailing comma:
	enum foo { one, two, three, };
is disallowed?

It sure looks that way.  (By the way, there's no way to sneak a
comma onto the end of an <enumeration-constant>.) I've been told
that nothing really changed from Dec 7, 88 to the final version,
but maybe this did, right?  (an aside: is it true that nothing
changed besides unary + ?)

If it really is disallowed, why?  It seems out of place, since
trailing commas are ok in array and struct initializers.  Why so
nitpicky here?  (gcc ignores the trailing comma unless you
specify -pedantic.)  Are compiler vendors likely to consider such
a comma a real live syntax error?  I suppose they have to.
(Maybe it was just too hard to specify the syntax to allow a
trailing comma? :-)

-- 
Richard Minner  || {uunet,sun,well}!island!rtm     (916) 736-1323 ||
                || Island Graphics Corporation     Sacramento, CA ||

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/20/90)

In article <8@christmas.UUCP> rtm@christmas.UUCP (Richard Minner) writes:
>mean that a trailing comma:
>	enum foo { one, two, three, };
>is disallowed?

Yes, the syntax does not permit a trailing comma after the list.
This was the result of an explicit vote in X3J11.  The basic argumentation
was that optional trailing comma after initializer lists was required by
the existing practice and had been deliberately intended (presumably to
facilitate automatic generation of such lists, although I find that a weak
reason), so that little bit of sloppiness had to be supported by the
standrad; however, it was generally felt that there was no need to extend
the syntactic sloppiness to the case of enumerator lists also.

>I've been told that nothing really changed from Dec 7, 88 to the final
>version, but maybe this did, right?  (an aside: is it true that nothing
>changed besides unary + ?)

I'm not exactly sure which draft that was, but it is dated after the
responses to the third formal public review, and since there were no
substantive changes made as a result of the third public review or
subsequent actions, just editorial clarifications etc., I suspect that
indeed the "Dec 7, 88" dpANS was substantially equivalent to the final
ANS.

>Are compiler vendors likely to consider such a comma a real live syntax
>error?  I suppose they have to.

Yes, syntax violations require a diagnostic.

>(Maybe it was just too hard to specify the syntax to allow a
>trailing comma? :-)

No, in fact X3J11 had several experts in formal syntax specification,
and could easily have allowed an optional comma if we had voted to do so.

meissner@osf.org (Michael Meissner) (08/20/90)

In article <8@christmas.UUCP> rtm@christmas.UUCP (Richard Minner)
writes:

| Is it just my eyes or does:
| 
| (From December 7, 1988 DRAFT)
| 3.5.2.2 Enumeration specifiers
| 
| Syntax
| 	<enum-specifier>:
| 		enum <identifier>_opt { <enumerator-list> }
| 		enum <identifier>
| 
| 	<enumerator-list>:
| 		<enumerator>
| 		<enumerator-list>, <enumerator>
| 
| 	<enumerator>:
| 		<enumeration-constant>
| 		<enumeration-constant> = <constant-expression>
| 		
| mean that a trailing comma:
| 	enum foo { one, two, three, };
| is disallowed?

Yes, trailing commas are not allowed for enum lists.

| If it really is disallowed, why?  It seems out of place, since
| trailing commas are ok in array and struct initializers.  Why so
| nitpicky here?  (gcc ignores the trailing comma unless you
| specify -pedantic.)  Are compiler vendors likely to consider such
| a comma a real live syntax error?  I suppose they have to.
| (Maybe it was just too hard to specify the syntax to allow a
| trailing comma? :-)

The original implementation of enum's also required a comma (or least
the documentation did not document that missing commas were allow, and
I don't have the source on-line), and ANSI reflects that.  My
recollection is it came up, but there was not enough sentiment to add
it.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?

jbw@zeb.uswest.com (Joe Wells) (08/25/90)

In article <13620@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug Gwyn) writes:

   Yes, the syntax does not permit a trailing comma after the list.
   This was the result of an explicit vote in X3J11.  The basic argumentation
   was that optional trailing comma after initializer lists was required by
   the existing practice and had been deliberately intended (presumably to
   facilitate automatic generation of such lists, although I find that a weak
   reason), so that little bit of sloppiness had to be supported by the
   standrad; however, it was generally felt that there was no need to extend
   the syntactic sloppiness to the case of enumerator lists also.

Why are trailing commas sloppy?  And even if they are "sloppy", what's
wrong with that?  Shouldn't you give the programmers what they want in
this case?

C uses trailing semicolons after expression statements.  Pascal uses
semicolons between statements.  How many people here prefer Pascal's less
"sloppy" semicolons?

-- 
Joe Wells <jbw@bu.edu, jbw@uswest.com>