Many thanks to all of you.
I got a reason for defining it to void* instead of char*, I should have included that in the question. My fault =) The reason is that my library can take diffrent types of objects, and therefor every other function I use is defined as taking void*. And thats also why I need the user to provide me with the comparator function (the lib dont know how to compare these 'void*' objects).
I have had problems with typedefing functions in the passed, thats why I didnt use it. Worth an other try..
To create a function pointer without arguments was a smart move, thats actually the same as providing it with a void argument.. but, does it work on all compilers? seems abit hazardous to do, as the user can send use _any_ function ;-).. But hey they could code a segfault in there function too.. I will use this, many thanks!!
...
Mm, created some testcode:
Code:
#include <stdio.h>
#include <stdlib.h>
void joy(int (*debug)()) {
debug("JOY\n");
}
int main() {
joy(printf);
return EXIT_SUCCESS;
}
But I got the following error while compiling:
test.c: In function `main':
test.c:10: warning: passing arg 1 of `joy' from incompatible pointer type
..
Is there any other way to solve this problem without getting a warning from the compiler?
If nothing else helps, maybe I have to ask the user to define a macro that I then use in a typedef in my headerfile and let it do some magic to get around this.. but I dont think thats an nice solution?