Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!utoday!comeau From: comeau@utoday.UUCP (Greg Comeau) Newsgroups: comp.lang.c++ Subject: Re: const enums -- Lawyers opinions?? Keywords: const, enum Message-ID: <1139@utoday.UUCP> Date: 9 Jan 90 05:06:53 GMT References: <963@rna.UUCP> Reply-To: comeau@.UUCP (Greg Comeau) Organization: UNIX Today!, Manhasset, NY Lines: 27 In article <963@rna.UUCP> kc@rna.UUCP (Kaare Christian) writes: >Is this a Zortechism, or is this standard C++ behavior? >enum bits { zero = 1, one = 2, two = 4 }; >bits ZeroAndOne = zero | one; // OK >const bits OneAndTwo = one | two; // Fails with ztc2.01 > // complaint is type mistmatch, had and >const bits OneAndTwoAgain = (const bits)one | (const bits)two; // OK > // but casts on the right look very redundant Actually what we have here for each case it a type mismatch since the only valid 'bits' are 'zero', 'one', and 'two'. A common extension in C and C++ is to let the assignment happen regardless (with a warning, not an error) because there is an enum/int conversion often present even if the given int is not a value enum "option" (value?). As to " and ", I'd say that is even worse than superfluous and is wrong since the | results in a respective promotion/ conversion producing an int which is similar to having said 'bits xyz = 5;' whether const or not. Actually, I'm a bit bewildered that the last case works since the result cannot be a 'bits' even if the bit pattern was ok, no less making each operand a const to make it work (although I think I see what it was doing). -- Greg, Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418 Also, mag writer for UNIX Today! (SysAdm columnist), Microsoft Systems Journal (C programming), + others. Also, BIX c.language & c.plus.plus conf. moderator. Here:attmail!csanta!greg / BIX:comeau / CIS:72331, 3421 / voice:718-849-2355