Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Enums

Reply
Thread Tools

Enums

 
 
borophyll@gmail.com
Guest
Posts: n/a
 
      09-25-2007
Hi all, what is the meaning of the second form of an enum declaration

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

as described in the spec. I couldn't see anywhere in the spec that
describes what this second form (with the extra comma) means?

Regards,
B.

 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      09-25-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> Hi all, what is the meaning of the second form of an enum declaration
>
> enum identifier { enumerator-list }
> enum identifier { enumerator-list , }
>
> as described in the spec. I couldn't see anywhere in the spec that
> describes what this second form (with the extra comma) means?
>
> Regards,
> B.


I'm not sure how "standard" it is, but it's a convenience in some
places. It has no meaning other than to facilitate adding of new enum
constants afaik.

enum MYENUMS {
FIRST=0,
SECOND,
THIRD,
}

The benefit is debatable but I like it. The idea being you can
rearrange, or cut and paste to your hearts content without keeping your
eagle eye on missing commas.

 
Reply With Quote
 
 
 
 
Pietro Cerutti
Guest
Posts: n/a
 
      09-25-2007
Richard wrote:
> (E-Mail Removed) writes:
>
>> Hi all, what is the meaning of the second form of an enum declaration
>>
>> enum identifier { enumerator-list }
>> enum identifier { enumerator-list , }
>>
>> as described in the spec. I couldn't see anywhere in the spec that
>> describes what this second form (with the extra comma) means?
>>
>> Regards,
>> B.

>
> I'm not sure how "standard" it is, but it's a convenience in some
> places. It has no meaning other than to facilitate adding of new enum
> constants afaik.


It's a new C99 feature, described by the Rationale as follows:

6.7.2.2 Enumeration specifiers
25
A new feature of C9X: a common extension in many implementations allows
a trailing comma
after the list of enumeration constants. The Committee decided to adopt
this feature as an
innocuous extension that mirrors the trailing commas allowed in
initializers.

>
> enum MYENUMS {
> FIRST=0,
> SECOND,
> THIRD,
> }
>
> The benefit is debatable but I like it. The idea being you can
> rearrange, or cut and paste to your hearts content without keeping your
> eagle eye on missing commas.
>



--
Pietro Cerutti

PGP Public Key:
http://gahr.ch/pgp
 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      09-25-2007
Richard wrote:
[...]
> I'm not sure how "standard" it is, but it's a convenience in some
> places. It has no meaning other than to facilitate adding of new enum
> constants afaik.
>
> enum MYENUMS {
> FIRST=0,
> SECOND,
> THIRD,
> }
>
> The benefit is debatable but I like it. The idea being you can
> rearrange, or cut and paste to your hearts content without keeping your
> eagle eye on missing commas.


Well, consider:

enum foo {
FIRST=0,
SECOND,
#ifdef ALLOW_THIRD
THIRD,
#endif
#ifdef ALLOW_FOURTH
FOURTH,
#endif
};

versus

enum foo {
FIRST=0,
SECOND
#ifdef ALLOW_THIRD
,THIRD
#endif
#ifdef ALLOW_FOURTH
,FOURTH
#endif
};

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <(E-Mail Removed)>


 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      09-25-2007
Kenneth Brody wrote:
> Richard wrote:
> [...]
>> I'm not sure how "standard" it is, but it's a convenience in some
>> places. It has no meaning other than to facilitate adding of new
>> enum constants afaik.
>>
>> enum MYENUMS {
>> FIRST=0,
>> SECOND,
>> THIRD,
>> }
>>
>> The benefit is debatable but I like it. The idea being you can
>> rearrange, or cut and paste to your hearts content without keeping
>> your eagle eye on missing commas.

>
> Well, consider:
>
> enum foo {
> FIRST=0,
> SECOND,
> #ifdef ALLOW_THIRD
> THIRD,
> #endif
> #ifdef ALLOW_FOURTH
> FOURTH,
> #endif
> };


No, consider:

enum MYENUMS{FIRST = 0
,SECOMD
,THIRD
}

which is trivially easily modified in future.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-25-2007
Kenneth Brody <(E-Mail Removed)> writes:

> Richard wrote:
> [...]
>> I'm not sure how "standard" it is, but it's a convenience in some
>> places. It has no meaning other than to facilitate adding of new enum
>> constants afaik.
>>
>> enum MYENUMS {
>> FIRST=0,
>> SECOND,
>> THIRD,
>> }
>>
>> The benefit is debatable but I like it. The idea being you can
>> rearrange, or cut and paste to your hearts content without keeping your
>> eagle eye on missing commas.

>
> Well, consider:
>
> enum foo {
> FIRST=0,
> SECOND,
> #ifdef ALLOW_THIRD
> THIRD,
> #endif
> #ifdef ALLOW_FOURTH
> FOURTH,
> #endif
> };
>
> versus
>
> enum foo {
> FIRST=0,
> SECOND
> #ifdef ALLOW_THIRD
> ,THIRD
> #endif
> #ifdef ALLOW_FOURTH
> ,FOURTH
> #endif
> };


For C90 code, there is also the option of:

enum foo {
FIRST=0,
SECOND,
#ifdef ALLOW_THIRD
THIRD,
#endif
#ifdef ALLOW_FOURTH
FOURTH,
#endif
DUMMY_FINAL_FOO_ENUM_FOR_SYNTACTIC_VALUE_ONLY
};

--
Ben.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      09-25-2007
Ben Bacarisse <(E-Mail Removed)> writes:

> Kenneth Brody <(E-Mail Removed)> writes:
>
>> Richard wrote:
>> [...]
>>> I'm not sure how "standard" it is, but it's a convenience in some
>>> places. It has no meaning other than to facilitate adding of new enum
>>> constants afaik.
>>>
>>> enum MYENUMS {
>>> FIRST=0,
>>> SECOND,
>>> THIRD,
>>> }
>>>
>>> The benefit is debatable but I like it. The idea being you can
>>> rearrange, or cut and paste to your hearts content without keeping your
>>> eagle eye on missing commas.

>>
>> Well, consider:
>>
>> enum foo {
>> FIRST=0,
>> SECOND,
>> #ifdef ALLOW_THIRD
>> THIRD,
>> #endif
>> #ifdef ALLOW_FOURTH
>> FOURTH,
>> #endif
>> };
>>
>> versus
>>
>> enum foo {
>> FIRST=0,
>> SECOND
>> #ifdef ALLOW_THIRD
>> ,THIRD
>> #endif
>> #ifdef ALLOW_FOURTH
>> ,FOURTH
>> #endif
>> };

>
> For C90 code, there is also the option of:
>
> enum foo {
> FIRST=0,
> SECOND,
> #ifdef ALLOW_THIRD
> THIRD,
> #endif
> #ifdef ALLOW_FOURTH
> FOURTH,
> #endif
> DUMMY_FINAL_FOO_ENUM_FOR_SYNTACTIC_VALUE_ONLY
> };


I'm happy that my view is supported by both examples.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      09-25-2007
CBFalconer <(E-Mail Removed)> writes:

>
> No, consider:
>
> enum MYENUMS{FIRST = 0
> ,SECOMD
> ,THIRD
> }
>
> which is trivially easily modified in future.
>


And simply "wrong" on the eye. *shrug*. IMO of course.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      09-26-2007
CBFalconer <(E-Mail Removed)> writes:
> Kenneth Brody wrote:
>> Richard wrote:
>> [...]
>>> I'm not sure how "standard" it is, but it's a convenience in some
>>> places. It has no meaning other than to facilitate adding of new
>>> enum constants afaik.
>>>
>>> enum MYENUMS {
>>> FIRST=0,
>>> SECOND,
>>> THIRD,
>>> }
>>>
>>> The benefit is debatable but I like it. The idea being you can
>>> rearrange, or cut and paste to your hearts content without keeping
>>> your eagle eye on missing commas.

>>
>> Well, consider:
>>
>> enum foo {
>> FIRST=0,
>> SECOND,
>> #ifdef ALLOW_THIRD
>> THIRD,
>> #endif
>> #ifdef ALLOW_FOURTH
>> FOURTH,
>> #endif
>> };

>
> No, consider:
>
> enum MYENUMS{FIRST = 0
> ,SECOMD
> ,THIRD
> }
>
> which is trivially easily modified in future.


Consider:

enum foo {
#ifdef ALLOW_FIRST
FIRST,
#endif
/* ... */
}

With the comma at the end of each line except the last, it's easily
modifiable unless you want to make a change at the end of the list.

With the comma at the beginning of each line except the first (which I
find much harder on the eyes), it's easily modifiable unless you want
to make a change at the beginning of the list.

With a comma on each line, as allowed by C99, it's easily modifiable
wherever you need to make a change.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Al Balmer
Guest
Posts: n/a
 
      09-26-2007
On Tue, 25 Sep 2007 18:02:54 -0400, CBFalconer <(E-Mail Removed)>
wrote:

>Kenneth Brody wrote:
>> Richard wrote:
>> [...]
>>> I'm not sure how "standard" it is, but it's a convenience in some
>>> places. It has no meaning other than to facilitate adding of new
>>> enum constants afaik.
>>>
>>> enum MYENUMS {
>>> FIRST=0,
>>> SECOND,
>>> THIRD,
>>> }
>>>
>>> The benefit is debatable but I like it. The idea being you can
>>> rearrange, or cut and paste to your hearts content without keeping
>>> your eagle eye on missing commas.

>>
>> Well, consider:
>>
>> enum foo {
>> FIRST=0,
>> SECOND,
>> #ifdef ALLOW_THIRD
>> THIRD,
>> #endif
>> #ifdef ALLOW_FOURTH
>> FOURTH,
>> #endif
>> };

>
>No, consider:
>
> enum MYENUMS{FIRST = 0
> ,SECOMD
> ,THIRD
> }
>
>which is trivially easily modified in future.
>

You've just moved the problem from the bottom to the top.

--
Al Balmer
Sun City, AZ
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enums without identifier, enums and typedef =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= C Programming 10 01-20-2007 01:20 AM
Storing Enums in web.config Matt ASP .Net 2 06-07-2005 01:45 PM
Basic question about enums Hans De Schrijver ASP .Net 1 06-05-2004 11:47 AM
enums martin ASP .Net 2 05-28-2004 04:48 PM
Loop through enums Syd ASP .Net 1 08-28-2003 09:49 PM



Advertisments