Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ibmps2!aix!nwosuck From: nwosuck@aix.aix.kingston.ibm.com (Kingsley Nwosu) Newsgroups: comp.os.minix Subject: Re: ARITHMETIC ON ENUMS? Message-ID: <3414@aix.aix.kingston.ibm.com> Date: 11 Sep 90 14:56:51 GMT References: <30007@nigel.ee.udel.edu> Organization: IBM Corporation, Kingston NY Lines: 46 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"