How should 'enum's work?

Kevin Martin kpmartin at watmath.UUCP
Tue Oct 30 15:12:51 AEST 1984


>>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



More information about the Comp.lang.c mailing list