Are there any guarantees regarding packing of structs in C?
Just as an example, provided that sizeof(double) == 8
, is it guaranteed that sizeof(struct { double x, y; }) == 16
?
I am aware that the intention behind this question conflicts with strict aliasing rules, therefore assume strict aliasing is disabled, e.g. in the case of gcc with -fno-strict-aliasing
.
To avoid any further speculations: The intention is knowing about compatibility of a struct with its explicitly packed counterpart. Note that aliasing is relevant even in the following case: Are C-structs with the same members types guaranteed to have the same layout in memory? . No need to worry about me wanting to access single bytes.