Suppress gcc warning when using function pointers with void* argument
Let's say I have function accepting function pointer as argument.
void fun(void(*problematicFunPointer)(void*) problemFun){
...
}
Then, when I want to use this function like this:
void actualProblematicFun1(struct s_something * smt){
...
}
void actualProblematicFun2(struct s_something_else * smthels){
...
}
int main(){
fun(&actualProblematicFun1);
fun(&actualProblematicFun2);
}
When using -Werror, this throws compile error -Werror=incompatible-pointer-types. Is there a way to suppress warning for this particular case?
Solution 1:
Is there a way to suppress warning for this particular case?
Write the actual functions with proper argument type that matches the declaration.
void actualProblematicFun1(struct s_something * smt){
...
}
void actualProblematicFun2(struct s_something_else * smthels){
...
}
void actualProblematicFun1Trampoline(void *smt) {
actualProblematicFun1(smt);
}
void actualProblematicFun2Trampoline(void *smthels) {
actualProblematicFun2(smthels);
}
int main(){
fun(&actualProblematicFun1Trampoline);
fun(&actualProblematicFun2Trampoline);
}