> cur_data is a global variable
Ugh, why isn't it a parameter?
Code:
static void dump(void *cur_data, const char *prefix, size_t size)
{
switch(size){
case sizeof(struct A): {
struct A *p = cur_data;
// do stuff with p->members
break;
}
case sizeof(struct B):
case sizeof(struct C);
default:
}
}
But this only works if all your structures have distinct sizes.
Normally you would have a variant structure as follows.
Code:
struct all {
int type;
union {
struct A a;
struct B b;
struct C c;
}v;
};
Where the .type member specifically identifies which of A,B,C is the real data representation.
You would then switch on .type in your generic handling.