www.digitalmars.com         C & C++   DMDScript  

D - BUG? Unions with inner structs

reply Sark7 <sark7 mail333.com> writes:
The program

union U
{
   struct { int a; }
   struct { int b; }
}

void main()
{
   printf("%d %d", U.a.offset, U.b.offset);
}

outputs:
   0 4

It is a bug or strange D feature?

--
Sark7
Feb 29 2004
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Sark7 wrote:

 The program
 
 union U
 {
   struct { int a; }
   struct { int b; }
 }
 
 void main()
 {
   printf("%d %d", U.a.offset, U.b.offset);
 }
 
 outputs:
   0 4
 
 It is a bug or strange D feature?

A bug that I've been about to report for a while, but you got there first. I found that it only happens with an anonymous inner struct - a predefined struct seems to work fine. It works if there is only one inner struct and it is put at the end (IIRC) of the union definition. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Mar 01 2004