union initalization
Johannes Pfau via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jul 22 02:02:10 PDT 2016
Am Fri, 22 Jul 2016 01:48:52 +0000
schrieb Rufus Smith <RufusSmith at indi.com>:
> I would like to combine two types
>
>
> template Foo(A, B = 4)
> {
> union
> {
> byte b = B;
> int a = A << 8;
> }
> }
>
>
> I get an error about overlapping default initialization. They
> don't actually overlap in this case because of the shift.
To be pedantic about this: The initializers actually do overlap. As A
<< 8 shifts in zeroes, these bits are initialized as well. I think
there's no idiomatic way to initialize only part of an integer.
More information about the Digitalmars-d-learn
mailing list