How many values in an enum (Was: Enumerated types... what's the point?)

P E Smee exspes at bath.ac.uk
Mon Apr 9 19:15:58 AEST 1990


In article <205 at caslon.cs.arizona.edu> dave at cs.arizona.edu (David P. Schaumann) writes:
>I think the practice of giving enum symbols explicit values as above is
>poor programming practice.  If you want a symbol with a specific value,
>you should use either #define first 2 or int first = 2, depending on what
>suits your context.  If you want a group of ordered symbols, use enum.
>
>It adds no
>functionality or expressiveness to the language, and opens up the door for
>untold misunderstandings.

Naw, it's a handy shorthand when you need a set of symbols (maybe
ordered and maybe not) which have distinct values, and where you DO
care about some of the values -- often for historical reasons.  The
fact that they become an indentifiable 'weak type' can help error
checking if you have a good (IMHO) lint -- and I do wish C itself
handled enums as strong types.  Lot quicker than having to #define AND
#typedef.

(In fact, in principle I see little philosophical difference between
allowing 'forced' values in enums, and allowing declaration of arrays
with a non-0 lower bound.  Three things arise from this.  First, I
agree with you in that I wish I could declare arrays which ranged over
the portion of space that I am interested in, rather than always having
to manually (or macro-ally) handle any offset myself.  Second, I'm a bit
surprised that the C-standard authors didn't include them.  And third,
I'm a bit surprised that you don't see a use for forced-value enums.)

-- 
Paul Smee, Computing Service, University of Bristol, Bristol BS8 1UD, UK
 P.Smee at bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132



More information about the Comp.lang.c mailing list