If you really wanted to use a macro, you could use a type-independent one like
Code:
#define void_deref(type, pointer) (*((type) *)(pointer))
which would be used as
Code:
void_deref(int, data);
void_deref(float, data);
Personally I don't find the syntax confusing enough to warrant a macro, but there's nothing wrong with it.
Also, an enum is a good candidate for the variable that indicates the type of the value pointed to by the void pointer.
Code:
enum type_t {
TYPE_INT,
TYPE_FLOAT
};
void sample(enum type_t type, void *data) {
switch(type) {
case TYPE_INT:
printf("INT=%d\n", *(int *)data);
break;
/* ... */
}
}
int i = 234;
sample(TYPE_INT, &i);
Just a thought.