enum: syntax question 
Author Message
 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  
 enum: syntax question


Wed, 18 Jun 1902 08:00:00 GMT  
 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  
 enum: syntax question


Wed, 18 Jun 1902 08:00:00 GMT  
 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  
 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  
 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  
 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  
 enum: syntax question


Wed, 18 Jun 1902 08:00:00 GMT  
 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  
 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  
 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  
 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  
 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  
 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  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. BUG: DEBUG member in enum in class syntax error C2059

2. 'C' enum syntax problem

3. C enum syntax problem

4. enum syntax

5. typedef enum as subset of another enum

6. enum - enum ?

7. enum - enum ?

8. newbie enum questions

9. enum questions

10. Newbie question: Enum for States

11. Quick Enum Question

12. Question of enum

 

 
Powered by phpBB® Forum Software