union.sizeof

zabruk70 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 25 23:38:59 PDT 2017


On Sunday, 26 March 2017 at 05:09:15 UTC, ketmar wrote:
> most of the time either location or padding will work the same.

hmm.. you ruined my expirence..

i made another experiment.
whould you please explain me S2 size 6?
thank you for you time.

https://dpaste.dzfl.pl/9a31b6e370a0

struct S1 //sizeof=6
{
   align(1):
   byte[3] b1; //offsetof=0, sizeof=3
   byte[3] b2; //offsetof=3, sizeof=3
}

struct S2 //sizeof must be 7, but DMD say 6
{
   align(4):
   byte[3] b1; //offsetof=0, sizeof=3
   byte[3] b2; //offsetof=4, sizeof=3
}



More information about the Digitalmars-d-learn mailing list