K
Konstantin Shemyak
I have a big structure tree. All leaves are scalar values (no pointers).
Present are arrays, structures and unions. I want to be able to store/read
the content of the structure in/from a file, and in a readable format.
This is needed to provide manually constructed test input to a function,
which works with this tree. Number of types is huge, and I want to avoid
hand-coding read/write functions for each type.
Ideally, I'm thinking about code which takes .h file with several
typedef-s and produces C code with functions for reading/writing these
structures. For example, for file "types.h", containing definitions like
typedef {...} TypeA;
I'll get file "ReadWriteTypes.c", containing functions like
TypeA* readTypeA(FILE* fp) {...}
void writeTypeA(TypeA* a, FILE* fp) {...}
And the file content will be, for example, similar to what debuggers
show when asked to print a nested data structure. I repeat that the
leaves contain only scalar values, no pointers.
Any hints how this can be done?
I use GNU tools, so sources of gcc and gdb are at my hands. Still
I am in hope that someone has already done this before...
Present are arrays, structures and unions. I want to be able to store/read
the content of the structure in/from a file, and in a readable format.
This is needed to provide manually constructed test input to a function,
which works with this tree. Number of types is huge, and I want to avoid
hand-coding read/write functions for each type.
Ideally, I'm thinking about code which takes .h file with several
typedef-s and produces C code with functions for reading/writing these
structures. For example, for file "types.h", containing definitions like
typedef {...} TypeA;
I'll get file "ReadWriteTypes.c", containing functions like
TypeA* readTypeA(FILE* fp) {...}
void writeTypeA(TypeA* a, FILE* fp) {...}
And the file content will be, for example, similar to what debuggers
show when asked to print a nested data structure. I repeat that the
leaves contain only scalar values, no pointers.
Any hints how this can be done?
I use GNU tools, so sources of gcc and gdb are at my hands. Still
I am in hope that someone has already done this before...