enums
guy at rlgvax.UUCP
guy at rlgvax.UUCP
Tue Jul 5 15:55:34 AEST 1983
The compiler you are referring to did not deliberately refuse to allow "switch"
on an enum; it was a compiler bug which has since been fixed. The original
VAX-11 PCC allowed "switch" on enums, and any port of the PCC to a new machine
should preserve that characteristic; this one fell through the cracks. The
fact that the names for the enums come out of a global pool is a more serious
problem; it was also a problem with structure members until the language was
changed for the System III compiler (which also comes with 4.?BSD). The same
change is a little more complex for enums; with structure members, you can
always disambiguate a member reference by looking at the type of the structure
being looked at, as the member is either being used as "foo.memb" or
"foop->memb" (and the compiler is somewhat insistent about NOT attaching a
member name to anything other than a structure of the proper type or a pointer
to such a structure). Enum member names, however, sit by themselves as plain
constants, and the only available context is the other terms of the expression.
You would have to insist on something like:
enum color { red, white, blue };
enum moon { new, quarter, half, full, harvest, blue };
enum color hue;
enum moon luna;
if (luna == moon.blue)
...
which is what somebody said in an earlier article was what ADA did. This
would require a somewhat incompatible extension to the language, although
one could elide the enum name if it was unambiguous ("white" would be
"color.white" as there is no "moon.white").
Guy Harris
{seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy
More information about the Comp.lang.c
mailing list