Enumerated types... what's the point?

Markku Savela Markku.Savela at tel.vtt.fi
Sat Mar 24 19:00:11 AEST 1990


>In article <1990Mar22.053148.10351 at ncsuvx.ncsu.edu> dks at shumv1.ncsu.edu (D. K. Smith) writes:
>>... 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.  

   There is one difference between #define and enum: you can do

	enum x { foo, bar, and, boo };
	...
	...
	int oops(foo)
	char *foo;
	  {
	     ...
	  }

   if you had "#define foo 0", you would at least get interesting
error messages from the compiler, not always quite easy to fathom,
unless you know to watch this situation...

   And, yes defining that kind of common names with #define is not
healthy. I don't usually do it, but got bitten by this when I
automaticly translated from Pascal to C (which converted Pascal
CONST-declarations to #define's ;-)  In a large program with
many included header files, it took a while until I realized what
the completely "bogus" error messages meant...



--
Markku Savela                         | savela at tel.vtt.fi
Technical Research Centre of Finland  |
Telecommunications Laboratory         | Markku.Savela at vtt.fi
Otakaari 7 B, SF-02150 ESPOO, Finland | savela%vtttel at router.funet.fi 



More information about the Comp.lang.c mailing list