Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!ugle.unit.no!nuug!ifi!enag From: enag@ifi.uio.no (Erik Naggum) Newsgroups: comp.lang.c Subject: Re: Are enums safe to use in portable code? Message-ID: Date: 31 Jan 91 23:37:15 GMT References: <22898@well.sf.ca.us> <1991Jan30.210255.16804@csrd.uiuc.edu> Sender: enag@ifi.uio.no (Erik Naggum) Organization: Naggum Software, Oslo, Norway Lines: 45 Nntp-Posting-Host: hild.ifi.uio.no In-Reply-To: bliss@sp64.csrd.uiuc.edu's message of 30 Jan 91 21:02:55 GMT Originator: enag@hild In article <1991Jan30.210255.16804@csrd.uiuc.edu>, Brian Bliss writes: The alliant fx C compiler (for an fx1 or fx8, not fx2800), supports them, but gives errors when you try to compare two enum constants. bb Assume these definitions: enum { frotz, klutz } foo; [1] enum { gunk, junk } bar; [2] Which of these are your compiler complaining against? frotz == klutz [3] frotz == gunk [4] frotz < klutz [5] frotz < junk [6] The declaration in [1] declares a distinct (anonymous) type of which foo is an object. Likewise [2] declares another distinct (anonymous) type of which bare is an object. frotz and klutz [1] are names of constant values of the type of object of which foo is an instance. Likewise for gunk and junk [2]. This makes the comparison in [3] valid (but slightly pointless), since we're comparing values of the same type, while the latter does not. In [5] and [6], "<" could be any of "<", "<=", ">", and ">=". I'm not sure about the welldefinedness of these comparisons, since I have seen compilers barf on expressions such as foo < klutz [7] since it implicitly entails a conversion to int, which nonetheless is the base type for enums. Careful consulting of the ANSI C standard may be needed to verify this. It would be helpful if you gave examples of the code on which your compilers gags, as well as the precise error message produced. -- [Erik Naggum] Snail: Naggum Software / BOX 1570 VIKA / 0118 OSLO / NORWAY Mail: , My opinions. Wail: +47-2-836-863 Another int'l standards dude.