If you want to be able to access variable size/type struct elements, then you would have to do something more advanced than that (a table of "type and offset" would work - I posted something like that not so long ago).
If you are just after dumping the information to say "This is the content", I guess all you need further is the size of the struct.
In either case, you would have to use a generic pointer type to get to the different members. In the simple case, a pointer to int or unsigned char would work. Unsigned char also works for the "using an offset" case.
Edit: For your case, something like this would work
Code:
typedef struct
{
int field[1];
} generic;
typedef struct {
int c1;
int c2;
} t_struct1;
typedef struct {
int c1;
int c2;
int c3;
} t_struct2;
void DumpStruct(const void * s, size_t size) {
generic *pg = s;
for (int i = 0; i < size / sizeof(*pg); i++) {
printf("Var %d = %d (%08x)\n", i, pg->field[i], pg->field[i]);
}
}
Of course, you could dump the value as bytes, using further casts if you like.
--
Mats