Packing of Struct Fields
anonymous at example.com
Sat Oct 17 12:51:21 UTC 2020
On 17.10.20 14:35, Per Nordlöw wrote:
> struct S
> int i;
> bool b;
> struct T
> S s; // reinterpreting this as an array can only access this first
> element anyway
> char c; // so why can't this be aligned directly after `s` without
> any padding?
c does come directly after s. The padding between b and c is part of s.
If you don't want that padding, you can use `align(1)` to define S
without padding. But then 75% of the ints in an S will be misaligned.
More information about the Digitalmars-d-learn