Thread overview
[Bug 44] New: forward referenced anonymous union in struct size discrepancy
Mar 12, 2006
d-bugmail
Mar 13, 2006
Thomas Kuehne
May 25, 2006
d-bugmail
March 12, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=44

           Summary: forward referenced anonymous union in struct size
                    discrepancy
           Product: D
           Version: 0.149
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: regan@netwin.co.nz


If B is declared before A, or the union in A is named (and an instance added) then the sizeof A is 12 as it should be. In the example below it is 8.

struct A {
        int a;
        union {
                int c;
                B b;
        }
}

struct B {
        int b1;
        int b2;
}

void main()
{
        A a;
        assert(A.sizeof == 12);
}


-- 

March 13, 2006
d-bugmail@puremagic.com schrieb am 2006-03-12:
> If B is declared before A, or the union in A is named (and an instance added) then the sizeof A is 12 as it should be. In the example below it is 8.
>
> struct A {
>         int a;
>         union {
>                 int c;
>                 B b;
>         }
> }
>
> struct B {
>         int b1;
>         int b2;
> }

Added to DStress as http://dstress.kuehne.cn/run/u/union_16_A.d http://dstress.kuehne.cn/run/u/union_16_B.d http://dstress.kuehne.cn/run/u/union_16_C.d http://dstress.kuehne.cn/run/u/union_16_D.d http://dstress.kuehne.cn/run/u/union_16_E.d http://dstress.kuehne.cn/run/u/union_16_F.d http://dstress.kuehne.cn/run/u/union_16_G.d http://dstress.kuehne.cn/run/u/union_16_H.d

Thomas


May 25, 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=44


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from bugzilla@digitalmars.com  2006-05-25 04:16 -------
Fixed 0.158


--