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.
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
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: <mailto:ThisIsA...@gmail.com>
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.
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
>
> 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.
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) ks...@mib.org <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"
You've just moved the problem from the bottom to the top.
--
Al Balmer
Sun City, AZ
The compiler will keep an eye on the syntax errors for you...
;^)
How about this macro hack:
____________
/* support */
#define ENUM_PUSH_FRONT(mp_name)mp_name
#define ENUM_PUSH_BACK(mp_name),mp_name
#define ENUM_PUSH_FRONT_EX(mp_name, mp_val) \
ENUM_PUSH_FRONT(mp_name) = (mp_val)
#define ENUM_PUSH_BACK_EX(mp_name, mp_val) \
ENUM_PUSH_BACK(mp_name) = (mp_val)
/* origin */
enum foo_e {
ENUM_PUSH_FRONT_EX(FOO_FLAG_ONE, 0x1)
ENUM_PUSH_BACK_EX(FOO_FLAG_TWO, 0x2)
ENUM_PUSH_BACK_EX(FOO_FLAG_THREE, 0x4)
ENUM_PUSH_BACK_EX(FOO_FLAG_FOUR, 0x8)
};
/* edited *//*
enum foo_e {
ENUM_PUSH_FRONT_EX(FOO_FLAG_ONE, 0x1)
ENUM_PUSH_BACK_EX(FOO_FLAG_TWO, 0x2)
ENUM_PUSH_BACK_EX(FOO_FLAG_THREE, 0x4)
ENUM_PUSH_BACK_EX(FOO_FLAG_FOUR, 0x8)
ENUM_PUSH_BACK_EX(FOO_FLAG_FIVE, 0x10)
ENUM_PUSH_BACK_EX(FOO_FLAG_SIX, 0x20)
};
*/
/* edited some more *//*
enum foo_e {
ENUM_PUSH_FRONT_EX(FOO_FLAG_ONE, 0x1)
ENUM_PUSH_BACK_EX(FOO_FLAG_TWO, 0x2)
ENUM_PUSH_BACK_EX(FOO_FLAG_THREE, 0x4)
ENUM_PUSH_BACK(FOO_SOMETHING)
ENUM_PUSH_BACK(FOO_SOMETHING_ELSE)
};
*/
____________
?