bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: spurious comma in sys/chown-core.c


From: James Youngman
Subject: Re: spurious comma in sys/chown-core.c
Date: Mon, 21 Feb 2005 19:39:04 +0000
User-agent: Mutt/1.3.28i

On Mon, Feb 21, 2005 at 01:17:23PM -0500, Daniel Reed wrote:
> On 2005-02-21T18:13+0100, Andreas Schwab wrote:
> ) Daniel Reed <address@hidden> writes:
> ) > On 2005-02-20T23:10-0800, Paul Eggert wrote:
> ) > ) -    RC_error,
> ) > ) +    RC_error
> ) > The comma is unnecessary but not illegal in C89 (confirmed by compiling
> ) > using gcc -std=c89).
> ) Try -pedantic.  The trailing comma is a C99 addition.
> 
> I only harp on this because I allow the presence of trailing commas in
> generated code, code that I trust is valid in traditional compilers.

I'm sure they accept it.  However, Paul is right.  Section 6.5.2.2
"Enumeration Specifiers" of the ANSI C standard (1989) says that
enumeration specifiers work like this:

  enum-sepcifier:
        enum identifier { enumerator-list }
        enum identifier
  
  enumerator-list:
        enumerator
        enumerator-list , enumerator
  
  enumerator:
        enumeration-constant
        enumeration-constant = constant-expression

Section 6.1.3.3 "Enumeration Constants" specifies...

  enumeration-constant:
        identifier

So, none of these production rules allow an enumerator-list to end in
a comma (since the comma in enumerator-list must always be followed by
an enumerator and an enumerator can also not end in a comma).

However, the same thing is not true for array initialisers.  Array
initialisers are indeed allowed to end with a comma.  Indeed, the
second example declaration in section 6.5.7 "Initialization" actually
does have a trailing comma, which underlines the point made in the
grammar:

  initializer:
        assignment-expression
        { initializer-list }
        { initializer-list , }

  initializer-list:
        initializer
        initializer-list , initializer

So I think Paul was right to make the patch, and the trailing comma is
indeed not allowed by ANSI C 1989, even though traditional compilers
might accept it.  After all, a compliant compiler is certainly not
required to reject all non-compliant programs.  It just has to be able
to translate at least one compliant program.  (Caveat: I'm looking at
the original standard, uncorrected by any of the technical/normative
corrigenda, but I don't remember this as having been changed).

Regards,
James.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]