Bug 44 – forward referenced anonymous union in struct size discrepancy

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-03-12T14:22:00Z
Last change time
2014-02-15T02:08:15Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
regan

Comments

Comment #0 by regan — 2006-03-12T14:22:17Z
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); }
Comment #1 by thomas-dloop — 2006-03-13T02:20:24Z
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 [email protected] 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-----
Comment #2 by bugzilla — 2006-05-25T04:16:54Z
Fixed 0.158