union initalization
Rufus Smith via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 21 18:48:52 PDT 2016
I would like to combine two types
template Foo(A, B = 4)
{
union
{
byte b = B;
int a = A << 8;
}
}
This packs a and b together in to an int bytes, saving an
int(rather than storing a and b in an int each) and makes it
easier to access.
I get an error about overlapping default initialization. They
don't actually overlap in this case because of the shift.
More information about the Digitalmars-d-learn
mailing list