Original link: Optimizing Struct Layout and Padding in Practice / Dev.
The example code is shown in Go, but it would be the same in C/C++ or another native language.