I have a c library function with the prototype:
int setCallback(void* callback_function);
It can accept a c function that matches
int myCallback(int x);
setCallBack(myCallback); // register function as callback
Now, I want to use this c library in a c++ project, and have it call a c++ function defined in a namespace. Passing the equivalent c++ function however, gives the error with g++ 5.4.0:
setCallBack(myCPPCallBack); // ERROR!
invalid conversion from ‘int (*)(int)’ to ‘void*’ [-fpermissive]
I can get it to build and run this by doing the following cast.
setCallBack((void*)myCPPCallBack);
My question is, is this undefined behavior or otherwise unwise to do so? What are the risks, and is there an alternative?