Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!dcl-cs!gdt!exspes From: exspes@bath.ac.uk (P E Smee) Newsgroups: comp.lang.c Subject: Re: How many values in an enum (Was: Enumerated types... what's the point?) Message-ID: <1990Apr9.091558.8578@bath.ac.uk> Date: 9 Apr 90 09:15:58 GMT References: <7152@uhccux.uhcc.hawaii.edu> <5152@rtech.rtech.com> <205@caslon.cs.arizona.edu> Organization: University of Bristol c/o University of Bath Lines: 30 In article <205@caslon.cs.arizona.edu> dave@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@bristol.ac.uk - ..!uunet!ukc!bsmail!p.smee - Tel +44 272 303132