* Re: First enum value defaults to zero?
2010-10-02 10:05 First enum value defaults to zero? Kristaps Dzonsons
@ 2010-10-02 15:06 ` Ingo Schwarze
0 siblings, 0 replies; 2+ messages in thread
From: Ingo Schwarze @ 2010-10-02 15:06 UTC (permalink / raw)
To: tech
Hi Kristaps,
Kristaps Dzonsons wrote on Sat, Oct 02, 2010 at 12:05:32PM +0200:
> Question for C-standard experts. Are initial enum entities
> guaranteed to be zero?
I won't try to answer that part.
> I understand the monotonicity is preserved (if it's not...),
> but can I blast the "= 0" scattered throughout our enums?
In case I don't rely on any particular assignment, I prefer to leave
the "= 0" out because in that case, it would make people wonder why
it's needed, distracting them from the actual meaning of the code.
In case i do rely on the numerical value of the first entry, i prefer
to make the "= 0" explicit no matter whether it is enforced by the
standard, just to make it clear that it is relevant to the program.
Probably, relying on numerical values of enums should be minimised,
anyway. All the same, i know of at least one case in mandoc where
it comes in handy:
enum mandoclevel {
MANDOCLEVEL_OK = 0,
MANDOCLEVEL_RESERVED,
MANDOCLEVEL_WARNING,
MANDOCLEVEL_ERROR,
MANDOCLEVEL_FATAL,
MANDOCLEVEL_BADARG,
MANDOCLEVEL_SYSERR,
MANDOCLEVEL_MAX
};
and then
return((int)exit_status);
But such use is certainly an exception.
Yours,
Ingo
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 2+ messages in thread