6 ms·
With the caveat that structs are padded by default so that members are aligned on architecture-friendly boundaries. For example, if a struct contains a char a
by pavlov 2y ago
With the caveat that structs are padded by default so that members are aligned on architecture-friendly boundaries.
For example, if a struct contains a char a followed by an int b, typically b would be at offset 4, even though sizeof(a) is 1.
To get tight packing, you need to explicitly tell the compiler to disable padding.
- pantalaimon 2y agoThat's why where is __attribute__((packed))