Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!hellgate.utah.edu!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Are enums safe to use in portable code? Message-ID: <9890@dog.ee.lbl.gov> Date: 14 Feb 91 08:25:48 GMT References: <22898@well.sf.ca.us> <1991Jan30.210255.16804@csrd.uiuc.edu> <128@tdatirv.UUCP> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 30 X-Local-Date: Thu, 14 Feb 91 00:25:48 PST In article <128@tdatirv.UUCP> sarima@tdatirv.UUCP (Stanley Friesen) writes: >According to 3.5.2.2 (Semantics): >"The identifiers in an enumerator list are declared as constants that >have type int and may appear anywhere such are permitted". Note, however, that a good compiler can (and probably should) emit a warning when enumeration constants for different enumerated types are compared. That is, given enum { apple, pear, orange } fruits; enum { lima, green, black } beans; a good compiler would complain differently about the comparision: if (apple == orange) than about the comparison: if (lima == pear) Both of these are effectively the same as `if (0)', hence a good compiler should warn about a constant in conditional context as well as mixing enumeration types (in the second example) and code that is not reached (assuming there are no labels following the comparisons). All of these are legal ANSI C expressions (despite the comparison of apples and oranges). Incidentally, one apple is worth a lot of Lima beans. :-) -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab EE div (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov