www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 44] New: forward referenced anonymous union in struct size discrepancy

reply d-bugmail puremagic.com writes:
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);
}


-- 
Mar 12 2006
next sibling parent Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 -----BEGIN PGP SIGNATURE----- iD8DBQFEFS7O3w+/yD4P9tIRAozZAJwKACUIQmALriijrOAxWHfi7NdvzgCbBzOg sJSwMb7zHxyIEEsqBkcE8qk= =WLwB -----END PGP SIGNATURE-----
Mar 13 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=44


bugzilla digitalmars.com changed:

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





Fixed 0.158


-- 
May 25 2006