union alignment

tsbockman via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 17 18:46:37 PDT 2016


Is this a bug?
---
module app;

union Foo(A, B) {
     A a;
     B b;
}

void main() {
     alias F = Foo!(double, ulong);

     import std.stdio, std.algorithm;
     writefln("sizeof:  (%s >= %s) == %s",
         F.sizeof, max(double.sizeof, ulong.sizeof),
         F.sizeof >= max(double.sizeof, ulong.sizeof));
     writefln("alignof: (%s >= %s) == %s",
         F.alignof, max(double.alignof, ulong.alignof),
         F.alignof >= max(double.alignof, ulong.alignof));
}
---
Shouldn't a union type always have an `alignof` at least as great 
as the `alignof` for its largest member?

DMD 64:
sizeof:  (8 >= 8) == true
alignof: (8 >= 8) == true

DMD 32:
sizeof:  (8 >= 8) == true
alignof: (4 >= 4) == true

GDC 64:
sizeof:  (8 >= 8) == true
alignof: (8 >= 8) == true

GDC 32:
sizeof:  (8 >= 8) == true
alignof: (4 >= 8) == false  <<===== Bug?

LDC 64:
sizeof:  (8 >= 8) == true
alignof: (8 >= 8) == true

LDC 32:
sizeof:  (8 >= 8) == true
alignof: (4 >= 4) == true



More information about the Digitalmars-d-learn mailing list