Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!dimacs.rutgers.edu!seismo!uunet!spool.mu.edu!sdd.hp.com!elroy.jpl.nasa.gov!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Are enums safe to use in portable code? Summary: go for it (well, maybe) Message-ID: <760@caslon.cs.arizona.edu> Date: 31 Jan 91 22:06:23 GMT References: <22898@well.sf.ca.us> <1991Jan30.210255.16804@csrd.uiuc.edu> <575@taumet.com> Organization: U of Arizona CS Dept, Tucson Lines: 43 bliss@sp64.csrd.uiuc.edu (Brian Bliss) writes: BB> The alliant fx C compiler (for an fx1 or fx8, not fx2800), supports BB> them, but gives errors when you try to compare two enum constants. steve@taumet.com (Stephen Clamage) writes: SC>Enums are well-defined and safe in standard (ANSI/ISO) C. However, SC>[there are pre-ANSI compilers out there that get them wrong]. SC>So if you need to port code among lots of pre-standard SC>or non-standard compilers, it is probably best not to use enums. (sarcasm 'on) Of course, if you want to port to a machine that doesn't have a C compiler at all, you'd better not even use C. Maybe you'll want to port to a machine that doesn't have a compiler that allows floating point numbers. Better not use those, either. Let us all now observe a moment of silence for the god Portability. (sarcasm 'off) (soapbox 'on) Portability is a slippery issue. People like to treat it like absolute portability is a reasonable and possible goal. But it is not possible to write a program that is absolutely portable to every platform on God's Green Earth. (By absolutely portable, I mean compilable/interpretable with *no* modifications whatsoever). Absolute portability is a grail no-one can reach. Realistic portability is balancing a trade-off. The wider the range of computers you wish to port to, the fewer language choices you have, and the fewer language features you can count on to be there and work right. Even if you restrict yourself to platforms that have some kind of C compiler, you are still faced with a wildly varying field of language features and qualities of implementation. To have even realistic portability, you have to expect at least a little editing on the target machine (in the general case). (soapbox 'off) If you're porting a program that uses enums to a compiler that doesn't have enums, or has broken enums, it is a fairly simple proceedure (in fact, it can be automated) to use #defines as a work-around. Dave Schaumann | And then -- what then? Then, future... dave@cs.arizona.edu | -Weather Report