Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site sequent.UUCP Path: utzoo!watmath!clyde!burl!we13!ihnp4!zehntel!tektronix!ogcvax!sequent!merlyn From: merlyn@sequent.UUCP Newsgroups: net.lang.c Subject: Re: Use of enumerations. Message-ID: <457@sequent.UUCP> Date: Wed, 18-Apr-84 12:01:19 EST Article-I.D.: sequent.457 Posted: Wed Apr 18 12:01:19 1984 Date-Received: Sat, 21-Apr-84 01:26:35 EST References: <155@celerity.UUCP> Organization: Sequent Computer Systems, Portland Lines: 50 ps@celerity.UUCP says: > 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. ... and then goes on to demonstrate that the compiler chokes when attempting to use enums like Pascal enumerated types. The main problem here is the assumption that "enum"s are like Pascal's enumerated types. They aren't. They're a funny kluge that keeps you from having to ALWAYS do "#define FOO 1", "#define BAR 2", etc. to get a distinguished set of constants. They don't operate much different than that, in fact. The main problem with producing the things you asked about is that an enum type (unlike the similar Pascal construct) is not necessarily dense. For example, for the declaration: enum weekday { sun, mon, tue, wed = 100, thu, fri, sat } today, tomorrow; what would "today++" or "tomorrow = today + 1" mean if "today" was "tue"??? Also, how many elements are there in an array indexed by "weekday"? As you can quickly see, you don't really get much more support with enums than the (roughly) equivalent: typedef int weekday; #define sun 1 /* or is it 0? can't remember now! */ #define mon 2 #define tue 3 #define wed 100 #define thu 101 #define fri 102 #define sat 103 except that you don't have to say all those "#define"s and it's a bit easier to add and delete items. Comments? Randal L. ("(null)") Schwartz, esq. (merlyn@sequent.UUCP) (Official legendary sorcerer of the 1984 Summer Olympics) Sequent Computer Systems, Inc. (503)626-5700 UUCP: ...!XXX!sequent!merlyn where XXX is one of: cdi decwrl nsc ogcvax pur-ee rocks34 shell unisoft vax135 verdix