Why doesn’t the compiler pack structs for you if it’s as easy as shuffling around based on type?
replies(1):
Why doesn’t the compiler pack structs for you if it’s as easy as shuffling around based on type?
Because the organization of your struct is exactly how the memory have to be organized and that might be important for you. The compiler doesn't know your intended usage so it can't rework the structure at its will.
For example, you might take the block of memory and data and send it to another system that will decode it. Or you can take the block of memory and store it in a file or in a hardware device where it means something in this specific order.