Struct members align in DMD 2.060

Maxim Fomin maxim at maxim-fomin.ru
Sun Oct 7 04:11:02 PDT 2012


On Sunday, 7 October 2012 at 10:45:40 UTC, novice2 wrote:
> Thanx Maxim,
> but what about
>
> S2.sizeof (should be 6) = 8
>
> S3.sizeof (should be 6) = 8

http://dpaste.dzfl.pl/57911897

Alignment attribute specifies members' alignment if it is inside 
structure and structure alignment if it is placed outside it. In 
case of S2 and S3 u member is placed without alignment and both 
structures contain 2+4 bytes, but because structures themselves 
are not specified with align() attribute, they are aligned to 
default 4 byte boundary and contain additional 2 trailing bytes. 
S4 is specified as having no alignment, so it's size is exactly 
2+4 bytes.


More information about the Digitalmars-d-learn mailing list