I am trying to compile some old code.
Depending on the compiler I get this warning/error when I try to assign a function pointer to a void*
pointer:
warning: a value of type "double (*)(double, double)" cannot be assigned to an entity of type "void *"
error: invalid conversion from ‘double (*)(double, double)’ to ‘void*’
I think that the old code used to compile on an old compiler but I understand that the code is illegal and shouldn't compile. I was wondering if there is a void*
for functions as well. I've tried this so far:
double sum(double a, double b){return a+b;}
typedef double(*dDd)(double, double);
typedef void(*vFun)(void);
dDd funPtr = sum; // compiles and works
void* vFunPtr = sum; // does not compile
vFun vFun_p = sum; // does not compile
but it fails to compile.
How can I fix this? I would be happy if there were a generalization of void*
to functions as well.