Based on the answer to the question Passing variable type as function parameter:
I could write something like this:
enum {
TYPEA,
TYPEB,
TYPEC,
TYPED
} TYPE;
void foo(TYPE t, void* x){
switch(t){
case TYPEA:
struct A* y = (struct A*)x;
//do something with a member named "next"
break;
case TYPEB:
struct B* y = (struct B*)x;
//do something with a member named "next"
...
}
}
Is there any way to avoid rewriting the "something with a member named next" multiple times?
We are assuming that "next" in A and B are not in the same relative memory position in each struct.