Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!asuvax!noao!arizona!dave From: dave@cs.arizona.edu (David P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Enumerated types... what's the point? Summary: This is the point Keywords: enums Message-ID: <159@caslon.cs.arizona.edu> Date: 22 Mar 90 22:34:57 GMT References: <1990Mar22.053148.10351@ncsuvx.ncsu.edu> Distribution: usa Organization: U of Arizona CS Dept, Tucson Lines: 39 In article <1990Mar22.053148.10351@ncsuvx.ncsu.edu>, dks@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@shumv1.ncsu.edu | ude.uscn.1vmuhs@skd | -my opinions reflect my opinions. | .snoinipo ym tcelfer snoinipo ym- | ------------------------------------------------------------------------ -------------------------------------------------------------------------- Dave Schaumann | These are my opinions. dave@cs.arizona.edu | --------------------------------------------------------------------------