HBO043%DJUKFA11.BITNET@cunyvm.cuny.edu (Christoph van Wuellen) (09/11/90)
Someone told me that my c68 compiler won't do arithmetic on enums (he complains that he cannot add two enums) This was made deliberately, I thought enums are symbolic constants, which make an ordered type. All kinds of comparisons should be fine with enums, but arithmetic? My K&R books says very little about enums (they came later). My decision is to let YOU decide if I should allow arithmetic on enums. C.v.W.
henry@zoo.toronto.edu (Henry Spencer) (09/11/90)
In article <30007@nigel.ee.udel.edu> HBO043%DJUKFA11.BITNET@cunyvm.cuny.edu (Christoph van Wuellen) writes: >Someone told me that my c68 compiler won't do arithmetic on enums >(he complains that he cannot add two enums) >This was made deliberately, I thought enums are symbolic constants, which >make an ordered type. >All kinds of comparisons should be fine with enums, but arithmetic? > >My K&R books says very little about enums (they came later). ANSI C says firmly that enums are a kind of integer. Compilers are entitled to whine about anything they consider dubious, but they must not refuse to compile it. This was a best-compromise minimum-code-breakage solution to a long-standing debate about the nature of enums. If you want to compile ANSI C, you need to fix this. Whether you like ANSI C or not, it has a far more precise definition and far wider acceptance than any other flavor of C. -- TCP/IP: handling tomorrow's loads today| Henry Spencer at U of Toronto Zoology OSI: handling yesterday's loads someday| henry@zoo.toronto.edu utzoo!henry
nwosuck@aix.aix.kingston.ibm.com (Kingsley Nwosu) (09/11/90)
In article <30007@nigel.ee.udel.edu> you write: >This was made deliberately, I thought enums are symbolic constants, which >make an ordered type. I don't quite agree that an enum makes an ordered type. Although not all C compilers implement enumerations, those that do are all inconsistent. The Draft Proposed ANSI C and most other current implementations allow enumerations constants to be assigned integer values by the programmer. Therefore, one can have an enum declaration like: enum example { small, big=10, smaller=1, bigger=-4, john=3}; >All kinds of comparisons should be fine with enums, but arithmetic? I wonder why? By its very nature, arithmetic computations should be possible across all implementations of enum. > >My K&R books says very little about enums (they came later). I do know the following about enum: (1) An enumeration is a set of integer values represented by identifiers(constants). (2) Integer vales are associated with the constants to facilitate comparisons and assignments. (3) The integer values can either be assigned by the programmmer or automatically. (4) The scope of an enum is the same as that of a variable. (5) Although the choice of using "short" or "long" is available in some implementations, the size of an enum is generally the size of type "int." (6) The value of zero is assigned to the first enum conatant if no explicit value is specified. (7) Other each successive enum constants is assigned an integer value that is one greater than its predecessor, if no explicit value assigned. (8) One can assign one integer value to more than one enum constants. >My decision is to let YOU decide if I should allow arithmetic on enums. Yes. I thank it makes a lot of sense. -- Kingsley Nwosu ...uunet!ibmps2!aix!nwosuck IBM AIX Dev., Dept. 83HA/572, |"All ambitions are lawful except those Neighborhood Rd, Kingston, NY 12401. |which climb upwards on the miseries (914)385-1100 |and credulities of mankind"