A way to find the size and location of padding in a struct?

前端 未结 10 2529
南笙
南笙 2020-12-16 02:49

I\'m trying to write a tool that will take as input some C code containing structs. It will compile the code, then find and output the size and offset of any padding the com

10条回答
  •  孤街浪徒
    2020-12-16 03:23

    If you have access to Visual C++, you can add the following pragma to have the compiler spit out where and how much padding was added:

    #pragma warning(enable : 4820) 
    

    At that point you can probably just consume the output of cl.exe and go party.

提交回复
热议问题