#What's the best way to have an unpadded struct with a fixed mem layout?
1 messages · Page 1 of 1 (latest)
an array of f32s will behave the same everywhere
and there won't be any padding, because its all aligned the same
extern struct defines a fixed memory layout (fields in declaration order, with padding to align each value to its type's alignment) which matches how C structs are laid out in practice. Technically a compliant C compiler can pad however much it wants, but in practice literally every ABI specifies behaviour that fits into this pattern, possibly just with different alignments for different types
If you want fields to be unaligned byte-packed, you can specify align(1) on your fields to avoid padding