Direct answer: it's not possible. Also, you should avoid writing such super functions that act on multiple types 2unless you can truly generalize the code and apply polymorphism. In C, that would often involve function pointers. Otherwise, there's nothing wrong with writing multiple functions that each act on a single type. In fact, that should be preferable over super functions.
Here's a basic example (not very useful, but simple):
#include <stdio.h>
typedef int less_function(void*, void*);
struct foo
{
int data;
};
int foo_less(void* a, void* b)
{
struct foo* f1 = a;
struct foo* f2 = b;
return f1->data < f2->data;
}
int find(void* search_array, void* element, int num, int element_size, less_function* less)
{
int j = 0;
char* search_pos = search_array;
for (j=0; j < num; ++j, search_pos += element_size)
{
// if current element == element to find
if (!less(search_pos, element) && !less(element, search_pos) )
return j;
}
return -1;
}
int main()
{
struct foo my_array[10] = { {0}, {1}, {2}, {3}, {4}, {5}, {6}, {123}, {7}, {8} };
struct foo search_element = {123};
// outputs 7
printf("%d\n", find(my_array, &search_element, 10, sizeof(struct foo), foo_less) );
}
In the above code, you can see that I don't have code like: if this type is an integer, do this, if it's a float, do that, if it's a struct foo object, do this, etc. Instead we rely on function pointers to provide the custom behavior for comparing the type of object being passed in.
qsort also does this and is a good example to look at. It's quite similar to the find function above, except its comparator doesn't simply return true/false based on whether the first object is less than the other: it's like strcmp and returns 0, -1, or +1.