Immutable unions

bearophile bearophileHUGS at lycos.com
Sun Mar 11 14:44:22 PDT 2012


Can you remind me why I can't define an immutable struct that contains an union, like this?


struct Foo1 {
    ushort bar2;
}
struct Foo2 {
    union  {
        ubyte[2] bar1;
        ushort bar2;
    }
}
void main() {
    immutable Foo1 foo1 = { bar2: 100 }; // OK
    immutable Foo2 foo2 = { bar2: 100 }; // error
}


The latest DMD gives:
test.d(12): Error: variable bug.main.foo2 is not a static and cannot have static initializer

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list