Problems with typechecking enumerated types
tallman at dspo.UUCP
tallman at dspo.UUCP
Wed Jul 11 09:55:39 AEST 1984
In the process of writing a new C compiler for the NS32032,
I have been trying some unusual expressions using enums on the
Berkley 4.2 C compiler on a Vax 11/780.
For example:
enum color {red,orange,yellow,green,blue,indigo,violet};
enum color crayon,rainbow;
main() {
int x[5];
x[yellow] = 1; /* causes "illegal type for +" error */
crayon = red*blue; /* no error or warning */
crayon = red + blue; /* no error or warning */
rainbow = red + 1; /* "enumeration type clash" warning */
rainbow = orange << 1; /* no error or warning */
rainbow = orange & 1; /* no error or warning */
if (rainbow > orange) x[1]=2; /* "illegal comparison of enums" */
if (rainbow == orange) x[1]=2; /* legal */
}
These results show the inconsistency in type checking enums - some
bizzare operations are allowed without any warning (like enum * enum)
and some reasonable operations are not allowed (like array indexing).
Has a standard been developed for what operations should and should not
be allowed on enums?
More information about the Comp.lang.c
mailing list