Article: The Lost Art of Structure Packing

Ogion ogion.art at gmail.com
Mon Nov 2 12:22:38 UTC 2026


On Monday, 2 November 2026 at 00:29:56 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> I found this rather nice article about padding in structs, it 
> also applies to D.

Maybe we need some way to allow the compiler rearrange the order 
of struct fields to optimally pack them, like it does with 
classes?

```D
struct S {
align (auto):
     byte a;    // placed at offset 0
     int b;     // placed at offset 4
     byte[3] c; // placed at offset 1
}
```

I’d even argue that auto-packing should be the default option.


More information about the Digitalmars-d mailing list