How do I create a list where each element can be of a different type?
What I am doing now is something along these lines:
typedef struct listitem
{
int flavour;
void *payload;
struct listitem *next;
} listitem
And when accessing an item from this list, I check the value of flavour and then cast payload to the appropriate type. This approach seems a bit sledge-hammer to me.
What is the standard way to do this in C99?
Is there someway to infer the type of an object, given only its address?