From: Ingo Schwarze <schwarze@usta.de>
To: tech@mdocml.bsd.lv
Subject: Re: First enum value defaults to zero?
Date: Sat, 2 Oct 2010 17:06:00 +0200 [thread overview]
Message-ID: <20101002150600.GA19515@iris.usta.de> (raw)
In-Reply-To: <4CA703EC.9060508@bsd.lv>
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
prev parent reply other threads:[~2010-10-02 15:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-02 10:05 Kristaps Dzonsons
2010-10-02 15:06 ` Ingo Schwarze [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20101002150600.GA19515@iris.usta.de \
--to=schwarze@usta.de \
--cc=tech@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).