However, you do this, unit test damn it. Compilers and platforms are very different at these points, so never blindly allow them to be consistent.
Compilers can change the alignment of the structure at their whim (for example, for performance reasons). Setting some restrictions is usually specific to the compiler, although this one is supported by MSVC and gcc (via extension)
#pragma pack(push, 1) struct Foo {
This forces it to align 1 byte, so there are no boolean elements.
If you want to be fully compatible, serialize each field yourself. It really doesn't work that much.
You will also have to deal with content, as others have mentioned.
source share