Packing of Struct Fields

Per Nordlöw per.nordlow at gmail.com
Sat Oct 17 12:35:37 UTC 2020


On Friday, 16 October 2020 at 21:26:12 UTC, Steven Schveighoffer 
wrote:
> To further explain this -- the padding is added so things like 
> pointer arithmetic on an array work.

In my code sample above one can only access the first element 
anyhow so I don't understand why this restriction is imposed here.

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?
}



More information about the Digitalmars-d-learn mailing list