Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 beta 5/9/83; site celerity.UUCP Path: utzoo!watmath!clyde!burl!ulysses!harpo!decvax!ittvax!dcdwest!sdcsvax!bmcg!celerity!ps From: ps@celerity.UUCP Newsgroups: net.lang.c Subject: Use of enumerations. Message-ID: <155@celerity.UUCP> Date: Tue, 17-Apr-84 08:54:32 EST Article-I.D.: celerity.155 Posted: Tue Apr 17 08:54:32 1984 Date-Received: Wed, 18-Apr-84 19:01:48 EST Organization: Celerity Computing Inc, San Diego Ca. Lines: 60 I have encountered a problem using enumerations with the 4.2bsd C compiler. The System 5 C Programming Guide states that the current language treats enumeration variables and constants as being of *int* type. There are apparently no special constructs in the language for incrementing and decrementing enumeration variables, and declaring arrays indexed by enumeration types. I assumed that the correct way of doing this would be to use the equivalent integer operations. However, the attached program causes the following error messages: "testwk.c", line 18: illegal comparison of enums "testwk.c", line 18: operands of ++ have incompatible types "testwk.c", line 19: operands of + have incompatible types "testwk.c", line 19: illegal indirection The compiler appears to be complaining about all uses of the enumeration type other than simple assignment and equality comparison. Is this how it ought to be? If so, enumerations are unlikely to be very useful. The following operations seem to be necessary: Increment and decrement, Compare, Array index, These operations are all available, for example, with Pascal scalar types. I would welcome suggestions for getting the same effects with C enumeration types, other than the use of excessive casting to integer. Type casting to integer works, but destroys much of the program clarity that the enumeration type should have gained. ========================================================================== main () { enum col { red, blue, green, black }; enum col colvar; static char *colstrings[] = { "red", "blue", "green", "black" }; for (colvar = red; colvar <= black; colvar++) printf ("%s\n", colstrings[colvar]); } -- ps (Pat Shanahan) uucp : {decvax!ucbvax || ihnp4 || philabs}!sdcsvax!celerity!ps arpa : sdcsvax!celerity!ps@nosc