Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site watmath.UUCP Path: utzoo!watmath!kpmartin From: kpmartin@watmath.UUCP (Kevin Martin) Newsgroups: net.lang.c Subject: Re: How should 'enum's work? Message-ID: <9634@watmath.UUCP> Date: Tue, 30-Oct-84 00:12:51 EST Article-I.D.: watmath.9634 Posted: Tue Oct 30 00:12:51 1984 Date-Received: Tue, 30-Oct-84 01:47:17 EST References: <9576@watmath.UUCP> <5495@brl-tgr.ARPA> Reply-To: kpmartin@watmath.UUCP (Kevin Martin) Organization: U of Waterloo, Ontario Lines: 31 >>I wrote: >Doug Gwyn writes: >> ... (although you should >> have to name 100 to ensure that the variable has enough range) > >I like all Kevin's suggestions on enums before this one. The intent of my comment about the 100 was indeed merely a note that the programmer must define the entire range, as well as the values he actually cares about. Otherwise, some clever compiler-writer might do some excessive bit-cramming (I don't know what either ANSI or various C compilers do about this) >> If you want to get fancy, you could enforce that *only* the enum type >> used in the dimension of an array declaration may be used to subscript >> that particular array... >Eh? What syntax for array declarations are we talking about here? enum primary {red, green, blue}; enum complementary {cyan, magenta, yellow}; int x[blue]; /* can only be subscripted with 'primary's */ int y[yellow]; /* can only be subscripted with 'complementary's */ Of course, the above wouldn't give quite enough space in the array. That's why the comment was only semi-serious. >> The conversion of an enum to char * through a direct cast should yield >> a string giving the enum identifier. >This would require storing all the enum names in run-time data space. >It would also be a rule unlike any other in C. I vote against this one. You only have to store the names if someone actually uses such a cast. How about casting into (char []) instead of (char *) ? :-) Kevin Martin, UofW Software Development Group