Enumerated types... what's the point?

Jamison Gray jamison at hobbes.Sun.COM
Sat Mar 24 05:33:58 AEST 1990


>In article <1990Mar22.053148.10351 at ncsuvx.ncsu.edu>, dks at 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 at Sun.COM            - Bob Dylan, "Everything's Broken"



More information about the Comp.lang.c mailing list