Why is too many commas allowed in enums?

D

DeMarcus

Hi,

In the code below there's an additional comma in the last line. Why is
this allowed? Is it harmless?

This compiles using g++ 4.4.3.

enum TooManyCommas
{
ONE,
TWO,
THREE,
};

int main()
{
TooManyCommas e;
return 0;
}


Thanks,
Daniel
 
V

Victor Bazarov

In the code below there's an additional comma in the last line. Why is
this allowed? Is it harmless?

This compiles using g++ 4.4.3.

enum TooManyCommas
{
ONE,
TWO,
THREE,
};

int main()
{
TooManyCommas e;
return 0;
}

It is harmless (and is defined in the Standard as "optional"), and
mostly designed to allow automatic generation of source code and spare
the programmer having to watch that the next token is the curly brace.
Allows to simplify editing of the enum declarations as well.

V
 
B

Balog Pal

Victor Bazarov said:
It is harmless (and is defined in the Standard as "optional")

Which standard? The current one actually does not allow the extra comma
(read the grammar in 7.2). Most compilers allow it as extension. C++0x will
allow it too.
, and mostly designed to allow automatic generation of source code and
spare the programmer having to watch that the next token is the curly
brace. Allows to simplify editing of the enum declarations as well.

It is certainly a sensible thing to allow.
 
D

DeMarcus

Which standard? The current one actually does not allow the extra comma
(read the grammar in 7.2). Most compilers allow it as extension. C++0x
will allow it too.


It is certainly a sensible thing to allow.

Thanks both of you!
 
G

Gennaro Prota

Which standard? The current one actually does not allow the extra
comma (read the grammar in 7.2). Most compilers allow it as
extension. C++0x will allow it too.

Core issue #518.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top