Switch to c++ and this becomes easy.
But the problem is one method can't do something with three different data formats. It would have to convert whatever data it needs into a standard format before using it. Or it would have to have a big switch statement for each type, in which case there is no point of having it be one method.
Your best option is to have several separate similarly named functions that convert the data to a common format to be used by the common function. If it is not possible to derive a common function that deals with the relevant data, but the structure of the code is the same for all variants, then you can use a macro for the common function, still keeping the struct specific functions to enforce type safety.
EDIT, for example the function above:
Code:
void function1A(StructA);
void function1B(StructB);
void function1C(StructC);
void function1_impliment(int size, char *data);
void function1A(StructA *struct){
function1_impliment(sizeof(StructA), (char*)struct);
}
void function1B(StructB *struct){
function1_impliment(sizeof(StructB), (char*)struct);
}
void function1C(StructC){
function1_impliment(sizeof(StructC), (char*)struct);
}
void function1_impliment(int size, char *data){
for (i=0; I < sizeof(anyStruct); i++) {
putchar();
}
}
Also to avoid code repletion you can use a macro like this:
Code:
#define function1_body(type) \
void function1##type(type*struct){
function1_impliment(sizeof(type), (char*)struct);
}
But you still need to call a different function for each type because C does not support overloading.
EDIT 2: I just realized that I am basically showing you how to implement templates in C. In C++ templates are much more common, though admittedly the code isn't much prettier.