473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

trailing commas at the end of enumeration

Hello,

I am working on a library in C++, and the library goes with a header file
with a trailing comma at the end of some enumeration. Like this:

enum Abc {
ENUM_ONE,
ENUM_TWO
ENUM_THREE,
#ifdef HAVE_SOMETHING
ENUM_FOUR,
#endif
ENUM_FIVE,
};

I believe this isn't very good to give away such a thing, because for
example
gcc with "-pedantic" flag barks at it with "error: comma at the end of
enumeration".
The library isn't mine, and the header file is generated, so this isn't
particularly
easy for me to make an edit.

I'm still not very sure if this is a bad style or not?
The C++ Standard (7.2) forbids such declaration:

enum-specifier:
enum identifier { enumerator-list }
enumerator-list:
enumerator-definition
enumerator-list , enumerator-definition
while C99 (6.7.2.2) clearly allows:

enum-specifier:
enum identifier { enumerator-list }
enum identifier { enumerator-list , }
enumerator-list:
enumerator
enumerator-list , enumerator

The question is: are those hanging commas ok or not?
Thanks!

Jan
Jun 27 '08 #1
6 9833
Jan Sneeuwman wrote:
The C++ Standard (7.2) forbids such declaration:
...
while C99 (6.7.2.2) clearly allows:
...
The question is: are those hanging commas ok or not?
You already answered your own question. Trailing comma in enum is illegal in
C89/90 and C++, but legal in C99. Which means that they are OK in C99 code only.

--
Best regards,
Andrey Tarasevich
Jun 27 '08 #2
Jan Sneeuwman wrote:
Hello,

I am working on a library in C++, and the library goes with a header file
with a trailing comma at the end of some enumeration. Like this:

enum Abc {
ENUM_ONE,
ENUM_TWO
ENUM_THREE,
#ifdef HAVE_SOMETHING
ENUM_FOUR,
#endif
ENUM_FIVE,
};

I believe this isn't very good to give away such a thing, because for
example
gcc with "-pedantic" flag barks at it with "error: comma at the end of
enumeration".
The library isn't mine, and the header file is generated, so this isn't
particularly
easy for me to make an edit.

I'm still not very sure if this is a bad style or not?
The C++ Standard (7.2) forbids such declaration:

enum-specifier:
enum identifier { enumerator-list }
enumerator-list:
enumerator-definition
enumerator-list , enumerator-definition
while C99 (6.7.2.2) clearly allows:

enum-specifier:
enum identifier { enumerator-list }
enum identifier { enumerator-list , }
enumerator-list:
enumerator
enumerator-list , enumerator

The question is: are those hanging commas ok or not?
Thanks!

Jan
In the generation of code, it is often inefficient to try and figure
whether to not emit the trailing comma. Sometimes there might be
emitted a range marker for the enum, which doesn't have a trailing
comma, so all the emitted enumerands (which seems to be a word) are
uniformly emitted, and the enumerator-list sequence doesn't end with a
comma.

http://www.nongnu.org/hcb/#enum-specifier
http://www.open-std.org/jtc1/sc22/wg...fects.html#518
No, they're not.

Ross F.
Jun 27 '08 #3
"Jan Sneeuwman" <ja***********@gmail.comwrote in message
news:b9******************************@giganews.com ...
Hello,

I am working on a library in C++, and the library goes with a header file
with a trailing comma at the end of some enumeration. Like this:

enum Abc {
ENUM_ONE,
ENUM_TWO
ENUM_THREE,
#ifdef HAVE_SOMETHING
ENUM_FOUR,
#endif
ENUM_FIVE,
};
[...]

Check this out:

http://groups.google.com/group/comp....5e6094ab2bc75e

Jun 27 '08 #4
On Apr 20, 11:07 pm, Jan Sneeuwman <jan.sneeuw...@gmail.comwrote:
I am working on a library in C++, and the library goes with a
header file with a trailing comma at the end of some
enumeration. Like this:
enum Abc {
ENUM_ONE,
ENUM_TWO
ENUM_THREE,
#ifdef HAVE_SOMETHING
ENUM_FOUR,
#endif
ENUM_FIVE,
};
I believe this isn't very good to give away such a thing,
because for example gcc with "-pedantic" flag barks at it with
"error: comma at the end of enumeration".
In C code, "gcc -std=c99 -pedantic" doesn't complain.
The library isn't mine, and the header file is generated, so
this isn't particularly easy for me to make an edit.
Then you may have to live with it, and not use the -pedantic
flag.
I'm still not very sure if this is a bad style or not? The
C++ Standard (7.2) forbids such declaration:
enum-specifier:
enum identifier { enumerator-list }
enumerator-list:
enumerator-definition
enumerator-list , enumerator-definition
So it's not a question of style; it's illegal.
while C99 (6.7.2.2) clearly allows:
enum-specifier:
enum identifier { enumerator-list }
enum identifier { enumerator-list , }
enumerator-list:
enumerator
enumerator-list , enumerator
The question is: are those hanging commas ok or not?
I believe that the orginal intent was always that they be legal.
Due to an oversight, there were illegal in C90, however, and C++
adopted the C90 definition of enums, so they're illegal in
C++03. The next version of C++ adopts C99 as its base, and they
will be legal.

In the meantime, however, while I might consider allowing them
for internal use, I certainly wouldn't deliver any code to
outside the firm which uses them.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #5
On Apr 21, 1:40 pm, James Kanze <james.ka...@gmail.comwrote:
[...] I certainly wouldn't deliver any code to
outside the firm which uses them.
Thank you all! I get it. The trailing commas won't be legal
until the new C++ standard is published. And the customer might
be disappointed (in case he'll use "-pedantic"),
and disappointed justly. Thank you!

Jan
Jun 27 '08 #6
On Apr 21, 1:40 pm, James Kanze <james.ka...@gmail.comwrote:
In C code, "gcc -std=c99 -pedantic" doesn't complain.
No, C++ code, of course. I meant "g++ -Wall -pedantic".

Jan
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Alberto Vera | last post by:
Hello: I have the next structure: How Can I make it using Python? How Can I update the value of 6?
1
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration...
0
by: Leo | last post by:
Can the value of the union datatype contain leading/trailing white space if it's not allowed by the member datatypes? For example, in the following example: t1.xsd: <?xml version="1.0"?>...
22
by: ineedyourluvin1 | last post by:
Hello all! I've been looking for a way to strip characters from strings such as a comma. This would be great for using a comma as a delimiter. I show you what I have right now. ...
5
by: Tammy | last post by:
I am doing some genealogy research and I have discovered that there is a lot of data available on the web in text format. The problem is that the columns in the files are lined up by spaces. I'd...
4
by: Marshal | last post by:
Sure... IEnumerable was inconvenient suggesting a separate class to service the enumeration, IEnumerator, and multiple operations: Current, MoveNext, Reset. (I'll warp the definition of "operation"...
4
by: striker | last post by:
I have a comma delimited text file that has multiple instances of multiple commas. Each file will contain approximatley 300 lines. For example: one, two, three,,,,four,five,,,,six one, two,...
14
by: bonehead | last post by:
Greetings, I'm using the DoCmd.TransferText method to export the results of a MS Access query to a csv file. The csv will then be used to load an Oracle table. In other systems such as TOAD...
3
by: garyusenet | last post by:
In my continuing education regarding string manipulation, can someone advise me how to take any trailing spaces, and commas from a string. these strings are comming from the streamreader ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.