Wrong sizes of extern/packed structs?

Packed structs are represented in memory using a backing integer. Access to fields is essentially a convenience feature around bitshifts. This means the backing integer is subject to the same alignment rules as regular integers. This means you will have padding in the most significant bits (highest memory address for little endian systems, lowest memory address for big endian systems).

readStruct is confusion and should probably be removed or modified from its current state in the std lib.

I use a lot of packed structs in my library because I have a binary protocol that can be defined using the little endian layout of a packed struct. You can find some examples of conversion functions etc here.

I also created this issue:

And you may be interested in this issue as well

4 Likes