473,326 Members | 2,104 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,326 software developers and data experts.

Is this a standard?

Hello,

enum eErrors
{
eSuccess = 0,
eErr1 = 1,
eErr2 = 2,
eErr3 = 3,
};

Notice the last comma. Is this allowed by the standard or the compiler?
Or even using: int ar[] = {1,2,3,};

p.s: VC++ 6
--
Elias
Jul 22 '05 #1
4 1328
lallous wrote:
Hello,

enum eErrors
{
eSuccess = 0,
eErr1 = 1,
eErr2 = 2,
eErr3 = 3,
};

Notice the last comma. Is this allowed by the standard or the compiler?
Or even using: int ar[] = {1,2,3,};

p.s: VC++ 6
--
Elias


Not in C++, but it used to be a common thing in C. The C++ grammar is

enum-specifier:
enum identifier(opt) { enumerator-list(opt) }
enumerator-list:
enumerator-definition
enumerator-list, enumerator-definition
enumerator-definition
enumerator
enumerator = constant-expression
enumerator:
identifier

Jul 22 '05 #2
On Fri, 9 Jan 2004 13:22:13 +0200, "lallous" <la*****@lgwm.org> wrote:
Hello,

enum eErrors
{
eSuccess = 0,
eErr1 = 1,
eErr2 = 2,
eErr3 = 3,
};

Notice the last comma. Is this allowed by the standard or the compiler?
That isn't standard (7.2/1 doesn't allow a terminating comma). Your
compiler may allow it as an extension (give it a go), but you should
avoid it.
Or even using: int ar[] = {1,2,3,};


That is standard (8.5/1 does optionally allow a terminating , for
aggregate initializers).

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3
lallous wrote:
Hello,

enum eErrors
{
eSuccess = 0,
eErr1 = 1,
eErr2 = 2,
eErr3 = 3,
};

Notice the last comma. Is this allowed by the standard or the compiler?
Or even using: int ar[] = {1,2,3,};


In C++ and C89/C90 the former is ill-formed, while the latter is OK. In
C99 both are OK.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #4
On Fri, 9 Jan 2004 13:22:13 +0200, "lallous" <la*****@lgwm.org> wrote
in comp.lang.c++:
Hello,

enum eErrors
{
eSuccess = 0,
eErr1 = 1,
eErr2 = 2,
eErr3 = 3,
};

Notice the last comma. Is this allowed by the standard or the compiler?
Or even using: int ar[] = {1,2,3,};

p.s: VC++ 6


The fact that the trailing comma is allowed in array initializations
but not in enum definitions was merely due to an accidental formatting
oversight in the 1989 ANSI C standard, adopted by ISO in 1990.

In the latest 1999 version of the C standard, the oversight was
corrected so if you have a C99 conforming compiler (and not many are),
the trailing comma is allowed in enums, but in C90 and C++, which
standard is based on the earlier C standard, it is illegal.

Many, perhaps most, C compilers and at least some C++ compilers accept
the trailing comma as a harmless extension.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #5

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

Similar topics

25
by: Magnus Lie Hetland | last post by:
Is there any interest in a (hypothetical) standard graph API (with 'graph' meaning a network, consisting of nodes and edges)? Yes, we have the standard ways of implementing graphs through (e.g.)...
6
by: John Bentley | last post by:
John Bentley writes at this level: If we think about our savings accounts then division never comes in (as far as I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
29
by: David Eng | last post by:
In replying to P.J. Plauger (...
43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
52
by: lovecreatesbeauty | last post by:
Why the C standard committee doesn't provide a standard implementation including the C compiler and library when the language standard document is published? C works on the abstract model of low...
24
by: noridotjabi | last post by:
Why isn't there a Graphical User Interface standard? Think about it for a second. You may say, well evey systems API for GUIs is differnt, but do take into acound: every operating system requires...
132
by: Frederick Gotham | last post by:
If we look at a programming language such as C++: When an updated Standard comes out, everyone adopts it and abandons the previous one. It seems though that things aren't so clear-cut in the C...
1
by: manish deshpande | last post by:
Hi, When i'm installing MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm by the following command: rpm -i MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm the following error is being shown: ...
26
by: Rick | last post by:
I'm told that "#pragma once" has made it into the ISO standard for either C or C++. I can't find any reference to that anywhere. If it's true, do any of you have a reference I can use? ...
270
by: jacob navia | last post by:
In my "Happy Christmas" message, I proposed a function to read a file into a RAM buffer and return that buffer or NULL if the file doesn't exist or some other error is found. It is interesting...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.