Find holes in C structs due to alignment

后端 未结 7 1288
难免孤独
难免孤独 2021-02-20 18:26

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

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 18:46

    You could explore this question by writing probe code for a particular struct using sizeof and &; if sizeof the nth member isn't equal to the address of the next member minus the address of that member, there's a hole.

提交回复
热议问题