enums

William E. Davidsen Jr davidsen at steinmetz.ge.com
Sat Jul 30 04:33:50 AEST 1988


A comment on the emum stuff lately...

In article <5447 at ihlpf.ATT.COM> nevin1 at ihlpf.UUCP (00704a-Liber,N.J.) writes:
| In article <1988Jul22.171612.6225 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
| >No.  X3J11 C (it's not quite officially ANSI C yet) almost didn't include
| >enums at all, since they are so obviously a crude patch onto the language.
| >It does in fact include them, in the simplest and stupidest form possible.

  Right on! enums were added because someone's preprocessor ran out of
symbols. Then a good version of enum couldn't be added because of "prior atr."
| 
| By saying that the dpANS C version of enums is 'the simplest and stupidest
| form possible', you have implied that there are much better forms of enums
| around.  Could you please enlighten us on to what these might be?

Here are my ideas on how an enum should work. Obviously no one gave me
definitive insight, so consider this as opinion from someone who's been
using computers for a while. If it looks a lot like Pascal, perhaps
that portion of the language is more useful than the bulk of it.

- enums should be a sequence of values in increasing order. The values
  should start at zero and increase by one. This allows the ++ and --
  operators to be used in a meaningful way.

- enums should not be conceptually mixed with ints. An explicit operation
  should be required to extract the ordinal value of an enum, and to set
  an enum to a value.

- it would be nice to have separate namespace for the various enum
  types. The current implementation treats enum names as if they were
  #defined values. This was a good idea for structs, and it's a good
  idea here. It allows development of modules wothout having to have a
  master control for enum names. Statements like x=red would specify the
  "red" for the enum type of x. enum type conversion could require a
  cast.

  My feeling is that the enum type is not quite abstract enough to
justify having another construct in the language.

-- 
	bill davidsen		(wedu at ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list