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 6 9870
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
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.
"Jan Sneeuwman" <ja***********@ gmail.comwrote in message
news:b9******** *************** *******@giganew s.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
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 objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Apr 21, 1:40 pm, James Kanze <james.ka...@gm ail.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
On Apr 21, 1:40 pm, James Kanze <james.ka...@gm ail.comwrote:
In C code, "gcc -std=c99 -pedantic" doesn't complain.
No, C++ code, of course. I meant "g++ -Wall -pedantic".
Jan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
|
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 value="red"/>
<xsd:enumeration value="yellow"/>
<xsd:enumeration value="blue"/>
</xsd:simpleType>
|
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"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.t1.org"
xmlns="http://www.t1.org"
elementFormDefault="qualified">
|
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.
#include<iostream>
#include<string>
int main(int argc, char *argv)
{
|
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 like to be
able to import these files into Access or Excel so that they can be
sorted.
What I plan on doing is adding in commas at the end of...
| |
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" for a second if you don't
mind).
However, it existed within intuitive language semantics, whereas the new
"yield" keyword, while highly...
|
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, three,four,,,,,,,,,,eighteen, and so on.
There is one time when multiple commas are allowed. Just prior to the
letters ADMNSRC there should be...
|
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 for Oracle, it's possible to force an
additional comma delimiter after the last column, if the column is empty
on a particular row. Oracle requires...
|
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
for instance.
string 1 = 'abcd '
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |