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
You could use Exuberant Ctags to parse your source files instead of using a CPAN module or hacking something up yourself. For instance, for the following code:
typedef struct _foo { int a; int b; } foo;
ctags emits the following:
_foo x.c /^typedef struct _foo {$/;" s file: a x.c /^ int a;$/;" m struct:_foo file: b x.c /^ int b;$/;" m struct:_foo file: foo x.c /^} foo;$/;" t typeref:struct:_foo file:
The first, fourth, and fifth columns should be enough for you to determine what struct types exist and what their members are. You could use that information to generate a C program that determines how much padding each struct type has.