Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cbatt!ihnp4!inuxc!pur-ee!uiucdcs!uiucdcsb!kraus From: kraus@uiucdcsb.UUCP Newsgroups: comp.lang.c++ Subject: Structures want anonymity, too. Message-ID: <165700008@uiucdcsb> Date: Sat, 28-Feb-87 16:51:00 EST Article-I.D.: uiucdcsb.165700008 Posted: Sat Feb 28 16:51:00 1987 Date-Received: Mon, 2-Mar-87 03:49:47 EST Lines: 45 Nf-ID: #N:uiucdcsb:165700008:000:1416 Nf-From: uiucdcsb.cs.uiuc.edu!kraus Feb 28 15:51:00 1987 Anonymous unions are nice. For example, page 67 of the C++ book gives the following example: struct entry { char* name; char type; union { char* string_value; // used if type=='s' int int_value; // used if type=='i' }; }; If "x" is an "entry", then one can get to the fields in the union with "x.string_value" and "x.int_value". (In C, one would have to give the union a name, which is annoying.) But why aren't there anonymous structures, too? For example, suppose that for some reason I also needed a flag in case type=='i'. I would like to say union { char* string_value; struct { int int_value; int flag; }; }; But this does not seem to be allowed. (I believe that it was version 1.1 that I tried this on.) So, I am forced to put "int flag" at the top level of the structure, which is annoying. It gets worse when lots of cases need several fields. The clearest solution that I have found is to have several anonymous unions in succession. It also seems the me that adding anonymous structures would increase the orthogonality of the language. Tim Kraus Department of Computer Science University of Illinois at Urbana-Champaign 1304 West Stringfield Avenue Urbana, IL 61801 USENET: {pur-ee,convex,ihnp4}!uiucdcs!kraus ARPA: kraus@b.cs.uiuc.edu CSNET: kraus%uiuc@csnet-relay