Author |
Message |
Neil Zanell #1 / 17
|
 enum: syntax question
Hello, I notice that gcc 3.2.2 compiles: enum { A, B, }; Is this really syntactically correct from the point of view of standard C99? I am surprised it compiles as I thought that for the declaration to be legal it would have to be written as enum { A, B }; with the extra comma deleted. Thanks, Neil
|
Mon, 24 Oct 2005 11:30:22 GMT |
|
 |
#2 / 17
|
 enum: syntax question
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Isaac Serruy #3 / 17
|
 enum: syntax question
Quote: > Hello, > I notice that gcc 3.2.2 compiles: > enum { A, B, }; > Is this really syntactically correct from the point > of view of standard C99? I am surprised it compiles > as I thought that for the declaration to be legal > it would have to be written as enum { A, B }; > with the extra comma deleted. > Thanks, > Neil
I'm not surprised but I don't know how this can harm a program or something like that :) It's just a poor comma, leave it alone man. About the C99 I really don't know what to tell you.
|
Mon, 24 Oct 2005 01:21:59 GMT |
|
 |
#4 / 17
|
 enum: syntax question
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Ben Pfaf #5 / 17
|
 enum: syntax question
Quote:
> I notice that gcc 3.2.2 compiles: > enum { A, B, };
This is valid C99 but not C90. -- "I hope, some day, to learn to read. It seems to be even harder than writing." --Richard Heathfield
|
Mon, 24 Oct 2005 12:16:55 GMT |
|
 |
Arthur J. O'Dwye #6 / 17
|
 enum: syntax question
Quote:
> > I notice that gcc 3.2.2 compiles: > > enum { A, B, }; > This is valid C99 but not C90.
Are you *sure* it's not valid C90? I seem to recall that from very early on C permitted trailing commas to facilitate the compilation of machine-generated C code. Or was that only in initializers like int x[] = { 10, 20, 30, 40, 23, 423, 234, 3, 223, 45, 643, 34, 34, 436, 45, 325, 23, 987, 34, 56, 23, 30, Quote: };
and not for enums? In any event, I expect it's a very widely supported extension at least. -Arthur
|
Mon, 24 Oct 2005 12:37:11 GMT |
|
 |
Ben Pfaf #7 / 17
|
 enum: syntax question
Quote:
> > > I notice that gcc 3.2.2 compiles: > > > enum { A, B, }; > > This is valid C99 but not C90. > Are you *sure* it's not valid C90?
Yes. I have a copy of C90 here, and the syntax doesn't allow it. I also have a copy of C99 here, and the syntax does allow it. Also, the foreword to C99 contains this item: - trailing comma allowed in enum declaration -- "...Almost makes you wonder why Heisenberg didn't include postinc/dec operators in the uncertainty principle. Which of course makes the above equivalent to Schrodinger's pointer..." --Anthony McDonald
|
Mon, 24 Oct 2005 13:06:48 GMT |
|
 |
Martin Ambuh #8 / 17
|
 enum: syntax question
Quote:
> Hello, > I notice that gcc 3.2.2 compiles: > enum { A, B, }; > Is this really syntactically correct from the point > of view of standard C99?
Yes, it is. Quote: > I am surprised it compiles > as I thought that for the declaration to be legal > it would have to be written as enum { A, B }; > with the extra comma deleted.
Don't be surprised; no, it doesn't need to be deleted.
|
Mon, 24 Oct 2005 17:22:55 GMT |
|
 |
#9 / 17
|
 enum: syntax question
|
Wed, 18 Jun 1902 08:00:00 GMT |
|
 |
Alan Balme #10 / 17
|
 enum: syntax question
On Wed, 7 May 2003 19:21:59 +0200, "Isaac Serruya" Quote:
>> Hello, >> I notice that gcc 3.2.2 compiles: >> enum { A, B, }; >> Is this really syntactically correct from the point >> of view of standard C99? I am surprised it compiles >> as I thought that for the declaration to be legal >> it would have to be written as enum { A, B }; >> with the extra comma deleted. >> Thanks, >> Neil >I'm not surprised but I don't know how this can harm a program or something >like that :) It's just a poor comma, leave it alone man. About the C99 I >really don't know what to tell you.
Explicitly allowed in C99. Intended as a convenience when adding new items to an enum. Same for structs - the last member declaration can have a comma after it. -- Al Balmer Balmer Consulting
|
Tue, 25 Oct 2005 00:52:52 GMT |
|
 |
Kevin Easto #11 / 17
|
 enum: syntax question
Quote:
> On Wed, 7 May 2003 19:21:59 +0200, "Isaac Serruya"
>>> Hello, >>> I notice that gcc 3.2.2 compiles: >>> enum { A, B, }; >>> Is this really syntactically correct from the point >>> of view of standard C99? I am surprised it compiles >>> as I thought that for the declaration to be legal >>> it would have to be written as enum { A, B }; >>> with the extra comma deleted. >>> Thanks, >>> Neil >>I'm not surprised but I don't know how this can harm a program or something >>like that :) It's just a poor comma, leave it alone man. About the C99 I >>really don't know what to tell you. > Explicitly allowed in C99. Intended as a convenience when adding new > items to an enum. Same for structs - the last member declaration can > have a comma after it.
comma? ITYM semicolon, and it's required, not just optional...? - Kevin.
|
Tue, 25 Oct 2005 07:24:10 GMT |
|
 |
Ben Pfaf #12 / 17
|
 enum: syntax question
Quote:
> > Explicitly allowed in C99. Intended as a convenience when adding new > > items to an enum. Same for structs - the last member declaration can > > have a comma after it. > comma? ITYM semicolon, and it's required, not just optional...?
Maybe he means a struct *initializer* can have a trailing comma. That statement is correct as far as it goes. -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." --Brian Kernighan
|
Tue, 25 Oct 2005 07:58:12 GMT |
|
 |
Alan Balme #13 / 17
|
 enum: syntax question
On Thu, 08 May 2003 23:24:10 GMT, Kevin Easton Quote:
>> On Wed, 7 May 2003 19:21:59 +0200, "Isaac Serruya"
>>>> Hello, >>>> I notice that gcc 3.2.2 compiles: >>>> enum { A, B, }; >>>> Is this really syntactically correct from the point >>>> of view of standard C99? I am surprised it compiles >>>> as I thought that for the declaration to be legal >>>> it would have to be written as enum { A, B }; >>>> with the extra comma deleted. >>>> Thanks, >>>> Neil >>>I'm not surprised but I don't know how this can harm a program or something >>>like that :) It's just a poor comma, leave it alone man. About the C99 I >>>really don't know what to tell you. >> Explicitly allowed in C99. Intended as a convenience when adding new >> items to an enum. Same for structs - the last member declaration can >> have a comma after it. >comma? ITYM semicolon, and it's required, not just optional...? > - Kevin.
Sorry, in my muddled way, I was simultaneously thinking of enum declarations and struct initializers. Must have been running low on caffeine. -- Al Balmer Balmer Consulting
|
Tue, 25 Oct 2005 23:16:12 GMT |
|
 |
Kevin Easto #14 / 17
|
 enum: syntax question
[... trailing commas ...] Quote: > Sorry, in my muddled way, I was simultaneously thinking of enum > declarations and struct initializers. Must have been running low on > caffeine.
Ahh, I see. It's not just struct initialisers, by the way, it's any initialiser in { }. (Do they have a name? "compound intialiser"?) - Kevin.
|
Wed, 26 Oct 2005 07:31:24 GMT |
|
 |
Dan P #15 / 17
|
 enum: syntax question
Quote: >Ahh, I see. It's not just struct initialisers, by the way, it's any >initialiser in { }. (Do they have a name? "compound intialiser"?)
What is compounded in the following initialiser: int i = { 1 }; Dan -- Dan Pop DESY Zeuthen, RZ group
|
Fri, 28 Oct 2005 23:00:32 GMT |
|
|
Page 1 of 2
|
[ 17 post ] |
|
Go to page:
[1]
[2] |
|