4 ms·
Optimization settings should not affect memory layout as that is specified by ABI (and large part of the “art of structure packing” is about manually reordering
by dfox 4y ago
Optimization settings should not affect memory layout as that is specified by ABI (and large part of the “art of structure packing” is about manually reordering struct fields because the compiler cannot do that however obvious the optimization would be).
And as for the second part: anything that writes sizeof(struct foo) bytes of struct foo is inherently non-portable. If you portably want to (de)serialize something you want to write the thing explicitly, very often the compiler will optimize it to more direct implementation. (And well, this is only portable to platforms where CHAR_BITS == 8)
- ncmncm 4y agoThe operative word is "should". Anything that affects the actual instructions executed on the actual chip they're executed on may make what works here not work there. Optimization that does not affect instructions is no optimization at all. Bitfields are an extremely fragile part of implementations. Trust it at your own risk.