union.sizeof
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Mar 25 15:43:17 PDT 2017
On 03/25/2017 11:37 PM, zabruk70 wrote:
> union Union1
> {
> align(1):
> byte[5] bytes5;
> struct
> {
> align(1):
> char char1;
> uint int1;
> }
> }
>
> void main ()
> {
> import std.stdio: writefln;
> writefln("Union1.sizeof=%d", Union1.sizeof); //prints 8, not 5
> }
I'm not sure how the align stuff is supposed to work exactly, but you
get 5 when you add `align(1)` to the union itself, too:
----
align(1) union Union1
{
align(1):
byte[5] bytes5;
struct
{
char char1;
uint int1;
}
}
pragma(msg, Union1.sizeof); /* "5LU" */
----
More information about the Digitalmars-d-learn
mailing list