Enumerated types... what's the point?

David P. Schaumann dave at cs.arizona.edu
Fri Mar 23 08:34:57 AEST 1990


In article <1990Mar22.053148.10351 at ncsuvx.ncsu.edu>, dks at shumv1.uucp (D. K. Smith) writes:
| 
| I thought... How nice!  These enumaerated types allow me "type check"
| myself when I am using them for distinguishing between different
| variable types that possess similar data structures.
| 
| [ example deleted ]
| 
| 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.  
| 
| I guess I am supposed to conclude that an int is an int is an int... no
| matter what kind of label you put on it?!?

The point of enums is that they offer more flexability than using #define.
For example, say you had a list of 100 symbols you wanted to use as constants.
Of course, order is important.  So, you type out 100 #defines.  Ok, fine.
Suddenly, you discover you need a new symbol, which should go between the
third and forth symbols.  If you use defines, you are pretty much stuck
retyping the values on 97 defines.  If you use enum, all you have to do
is insert the name in the list, and continue on your merry way.
Also, if you use #defines, you may be tempted by your explicit knowledge of
the value of that symbol to use it in some way that would break if you
change the value.
| 
| 
| dk smith
| ------------------------------------------------------------------------
| dks at shumv1.ncsu.edu                |                ude.uscn.1vmuhs at skd
| -my opinions reflect my opinions.  |  .snoinipo ym tcelfer snoinipo ym-
| ------------------------------------------------------------------------


--------------------------------------------------------------------------
Dave Schaumann		| These are my opinions.
dave at cs.arizona.edu	| 
--------------------------------------------------------------------------



More information about the Comp.lang.c mailing list