Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site dspo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!houxz!vax135!cornell!uw-beaver!tektronix!hplabs!hao!seismo!cmcl2!lanl-a!dspo!tallman From: tallman@dspo.UUCP Newsgroups: net.lang.c Subject: Problems with typechecking enumerated types Message-ID: <109@dspo.UUCP> Date: Tue, 10-Jul-84 19:55:39 EDT Article-I.D.: dspo.109 Posted: Tue Jul 10 19:55:39 1984 Date-Received: Fri, 13-Jul-84 03:13:55 EDT Organization: Los Alamos Natl. Labs - DSPO; Los Alamos, NM Lines: 28 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?