Path: utzoo!attcan!uunet!husc6!cca!alex From: alex@cca.CCA.COM (Alexis Layton) Newsgroups: comp.lang.c Subject: Re: enums Summary: dpANS C enums need better type-checking Message-ID: <31416@cca.CCA.COM> Date: 27 Jul 88 21:12:06 GMT References: <1608@dataio.Data-IO.COM> <469@m3.mfci.UUCP> <1988Jul22.171612.6225@utzoo.uucp> <5447@ihlpf.ATT.COM> Reply-To: alex@CCA.CCA.COM (Alexis Layton) Organization: Computer Corp. of America, Cambridge, MA Lines: 44 To jump into this fray, I think I'd have to agree with Henry. Enums are completely superfluous if they do not provide both type-checking and better storage control. I would like to see enum have the following type-checking properties: convertible to and from ints automatically, but only assignable to enums of the same type. This is very much like the relationship between pointers and pointers to void. enum able { Alpha, Beta }; enum baker { Red, Green }; enum able a; enum baker b; int i; a = Alpha; /* ok */ b = Green; /* ok */ a = Green; /* oops: wrong type */ a = b; /* ditto */ a = 6; /* ok, ints convertible to enums */ i = a; /* ok, enums convertible to ints */ b = i; /* also ok */ i = Green; /* ok */ Actually, it may be better to restrict int->enum; so that "a = 6" above would fail without explicit cast. But enum->int must be allowed (which the pcc does not), so you can have char *baker_names[] = { "Red", "Green" }; and say printf("%s\n", enum_names[b]); A second useful thing with enums would be if the "short" and "long" adjectives would apply to them. (You'd also like a "char"-size one, but "char" is not an adjective; don't know just what to do about this, maybe "byte"?) Then you could easily specify smaller enumeration sizes without using bitfields. Well, it's probably too late now for the ANSII standard; but maybe on the next go-around (you know, NEXT year.... :-) ) this might be looked into. Alexis Layton alex@CCA.CCA.COM