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

前端 未结 10 2472
南笙
南笙 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:02

    I prefer to read and write into a buffer, then have a function load the structure members from the buffer. This is more portable than reading directly into a structure or using memcpy. Also this algorithm frees up any worry about compiler padding and can also be adjusted to handle Endianess.

    A correct and robust program is worth more than any time spent compacting binary data.

提交回复
热议问题