Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ames!amdcad!sun!hobbes!jamison From: jamison@hobbes.Sun.COM (Jamison Gray) Newsgroups: comp.lang.c Subject: Re: Enumerated types... what's the point? Keywords: enums Message-ID: <133372@sun.Eng.Sun.COM> Date: 23 Mar 90 19:33:58 GMT References: <1990Mar22.053148.10351@ncsuvx.ncsu.edu> <159@caslon.cs.arizona.edu> Sender: news@sun.Eng.Sun.COM Reply-To: jamison@sun.UUCP (Jamison Gray) Distribution: usa Organization: Sun Microsystems, Mountain View Lines: 27 >In article <1990Mar22.053148.10351@ncsuvx.ncsu.edu>, dks@shumv1.uucp (D. K. Smith) writes: >| However, to my surprise, I discovered that I could interchange these >| critters among themselves as well as with Booleans! Is this what is >| supposed to happen? I have not RTFM'd the C scriptures but my >| immediate reaction is "what's the point!...I could just as easily >| used #define and accomplished the same thing. Another advantage enumerated types have over #define'ed constants is that they're handled by the compiler, rather than cpp. As a result, a debugging compiler (and thus a debugger) can know about the names associated with a value. In the dbx debugger on a Sun, for instance, printing out the value of a variable with an enumerated type gives you the symbolic name, which is generally a whole lot more helpful than the integer value. For example, the Phigs Ptxalign type is a structure of two enumerated types. Here's what I get when I print one out: (dbxtool) print ptxalign ptxalign = { hor = PAH_LEFT ver = PAV_HALF } -- Jamie Gray Jamie Gray, Sun Microsystems "Broken pipes; broken tools; Mountain View, CA People bendin' broken rules" Internet: jamison@Sun.COM - Bob Dylan, "Everything's Broken"