Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!uxc.cso.uiuc.edu!garcon!uicsrd.csrd.uiuc.edu!mcdaniel From: mcdaniel@uicsrd.csrd.uiuc.edu (Tim McDaniel) Newsgroups: comp.lang.c++ Subject: Re: errata in C++ Primer Message-ID: <1304@garcon.cso.uiuc.edu> Date: 19 Jun 89 19:26:44 GMT References: <883@kaiser.UUCP> Sender: news@garcon.cso.uiuc.edu Reply-To: mcdaniel@uicsrd.csrd.uiuc.edu (Tim McDaniel) Organization: Center for Supercomputing R&D (Cedar), U. of Ill. Lines: 72 [I'm sorry if the original cancelled one gets out, too.] In article <883@kaiser.UUCP> stan@kaiser.UUCP (s Lippman) writes: >p.40 : named enumerations now define unique integral > types. For example, > > enum TestStatus { NOT_RUN=-1, FAIL, PASS }; > enum Boolean { FALSE, TRUE }; > > main() { > TestStatus test = NOT_RUN; > Boolean found = FALSE; > > test = -1; // error: TestStatus = int > test = 10; // error: TestStatus = int > test = found; // error: TestStatus = Boolean > test = FALSE; // error: TestStatus = const Boolean > int st = test; // ok: implicit conversion > } I'd like to see more details on what the semantics exactly are. The only examples here are for assignment, but for full clarity, I need to know the results of applying any operator to an enum operand. What happens when I have values and operations like: enum_X enum_X => enum_X ? Y* enum_X => Y* or error? int enum_X => enum_X or error? type var[enum_X]; => tye var[(int) enum_X]; or error? Any other cases I've neglected? Suppose I want to count the number of times NOT_RUN, FAIL, and PASS occur. So I'd actually do something like this: enum TestStatus { NOT_RUN, FAIL, PASS, MAX_TEST }; int status_count[MAX_TEST]; for (TestStatus i = NOT_RUN; i < MAX_TEST; i++) status_count[i] = 0; enum TestStatus rc; while (dotest(&rc)) status_count[rc]++; Is this legal or not? I'd hate to have to muck about with int status_count[(int) MAX_TEST]; ... status_count[(int) rc]++; > int st = test; // ok: implicit conversion Bleah. Are there any other cases in C++ where type var = expr; is not equivalent to type var; var = expr; ? Are there any other possible "implicit conversions"? >p.40 : named enumerations now define unique integral types What's a "named enumeration"? Is typedef enum {FOO, BAR} widget; a named enumeration? What if we have enum {FOO, BAR} a; a = 1; // legal or no? Why are "named" enumerations distinguished from "unnamed" ones? -- "Let me control a planet's oxygen supply, and I don't care who makes the laws." - GREAT CTHUHLU'S STARRY WISDOM BAND (via Roger Leroux) __ \ Tim, the Bizarre and Oddly-Dressed Enchanter \ mcdaniel@uicsrd.csrd.uiuc.edu /\ mcdaniel%uicsrd@{uxc.cso.uiuc.edu,uiuc.csnet} _/ \_ {uunet,convex,pur-ee}!uiucuxc!uicsrd!mcdaniel