Path: utzoo!utgpu!attcan!uunet!mcvax!ukc!strath-cs!glasgow!orr From: orr@cs.glasgow.ac.uk (Fraser Orr) Newsgroups: comp.lang.c Subject: Re: enums Message-ID: <1542@crete.cs.glasgow.ac.uk> Date: 29 Jul 88 12:31:41 GMT References: <1608@dataio.Data-IO.COM> <469@m3.mfci.UUCP> <1988Jul22.171612.6225@utzoo.uucp> <5447@ihlpf.ATT.COM> <31416@cca.CCA.COM> Reply-To: orr@cs.glasgow.ac.uk (Fraser Orr) Organization: Comp Sci, Glasgow Univ, Scotland Lines: 38 In article <31416@cca.CCA.COM> alex@CCA.CCA.COM (Alexis Layton) writes: > >Actually, it may be better to restrict int->enum; so that "a = 6" above >would fail without explicit cast. I agree. In fact, if you have any pretentions to having a reasonable type system, then this MUST be the case. >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]); > Alternatively, you could have a decleration syntax, that allowed this: char * baker_names [ enum baker ] = {"Red", "Green" } ; and then printf("%s\n", baker_names[b]); /* Legal */ printf("%s\n", baker_names[i]); /* Illegal */ printf("%s\n", baker_names[a]); /* Illegal */ would be completely type secure, and the purpose of baker_names would be much more apparent to the reader. A previous poster ( sorry I've lost the article) asked how you could find the number of elements in an enum. Can anyone tellme why such information would be useful (appart from in array size declerations)? ==Fraser Orr ( Dept C.S., Univ. Glasgow, Glasgow, G12 8QQ, UK) UseNet: {uk}!cs.glasgow.ac.uk!orr JANET: orr@uk.ac.glasgow.cs ARPANet(preferred xAtlantic): orr%cs.glasgow.ac.uk@nss.cs.ucl.ac.uk