From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o92F623w002033 for ; Sat, 2 Oct 2010 11:06:04 -0400 (EDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1P23ey-0007ku-VT; Sat, 02 Oct 2010 17:06:01 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.71) (envelope-from ) id 1P23ey-0003Z6-RG for tech@mdocml.bsd.lv; Sat, 02 Oct 2010 17:06:00 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1P23ey-0005Px-QQ for tech@mdocml.bsd.lv; Sat, 02 Oct 2010 17:06:00 +0200 Received: from schwarze by usta.de with local (Exim 4.71) (envelope-from ) id 1P23ey-000280-IR for tech@mdocml.bsd.lv; Sat, 02 Oct 2010 17:06:00 +0200 Date: Sat, 2 Oct 2010 17:06:00 +0200 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: Re: First enum value defaults to zero? Message-ID: <20101002150600.GA19515@iris.usta.de> References: <4CA703EC.9060508@bsd.lv> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4CA703EC.9060508@bsd.lv> User-Agent: Mutt/1.5.20 (2009-06-14) 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