Is there a way in gcc or clang (or any other compiler) to spit information about whether a struct has holes (memory alignment - wise) in it ?
Thank you.
ps: If there is another way to do it, please do inform me.
Assuming a 64-bit machine, any instance of struct foo1 will have 8-byte alignment.
General Byte Alignment Rules Structures between 1 and 4 bytes of data should be padded so that the total structure is 4 bytes. Structures between 5 and 8 bytes of data should be padded so that the total structure is 8 bytes.
4.11 The __packed__ Attribute This attribute, attached to struct or union type definition, specifies that each member (other than zero-width bitfields) of the structure or union is placed to minimize the memory required. When attached to an enum definition, it indicates that the smallest integral type should be used.
Structure padding is a concept in C that adds the one or more empty bytes between the memory addresses to align the data in memory.
You can use pahole
to output information about holes in structures and optionally attempt packing them.
You may want to read "Poke-a-hole and friends" and the pahole announcement for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With