Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!columbia!rutgers!labrea!Shasta!satz From: satz@Shasta.STANFORD.EDU (Greg Satz) Newsgroups: comp.lang.c++ Subject: bug with unions? Message-ID: <1910@Shasta.STANFORD.EDU> Date: Tue, 4-Aug-87 13:48:57 EDT Article-I.D.: Shasta.1910 Posted: Tue Aug 4 13:48:57 1987 Date-Received: Thu, 6-Aug-87 02:29:14 EDT Reply-To: satz@Shasta.UUCP (Greg Satz) Organization: Stanford University Lines: 66 While trying to convert some code to use cfront I came across the following anomoly. When declaring a union with structs contained within, if the struct definitions contain tags, the resulting union generated is empty. However if you remove the struct tags, the union is generated with the structs correctly. Following is the C++ source and the generated C code. This C++ code: union ttype { struct na { unsigned short hint; unsigned short pint; } na; struct pl { unsigned char nint; unsigned char next; unsigned long n; unsigned char data[2]; } pl; struct err { unsigned short reason; char copy[2]; } err; }; generates this C code: # 1 "" /* <> */ # 1 "" int *_new (); # 1 "" int _delete (); # 1 "" int *_vec_new (); # 1 "" int _vec_delete (); # 1 "" struct na { /* sizeof = 4 */ # 3 "" unsigned short _na_hint ; unsigned short _na_pint ; } ; struct pl { /* sizeof = 12 */ unsigned char _pl_nint ; unsigned char _pl_next ; unsigned long _pl_n ; unsigned char _pl_data [2]; } ; struct err { /* sizeof = 4 */ unsigned short _err_reason ; char _err_copy [2]; } ; union ttype { /* sizeof = 12 */ /** The size is correct **/ } ; /** but the result is empty. **/ /* the end */