Function pointers

closed account (DGvMDjzh)
Ive been recently experimenting with function pointers and I got into a problem.

This is a basic function pointer:

 
void (*pFunc)(int,float) = &Func;

Which works fine, but how do you point to a function if you only have the address?


This obviously wouldn't work:

 
void (*pFunc)(int,float) = 0xFFFFFF;


Common sense tells me to try this, but it still fails:

1
2
void (*pFunc)(int,float) = NULL;
pFunc = *(pFunc*)0xFFFFFF;


So what's the correct way to approach this issue?
1
2
void (*pFunc)(int,float) = NULL;
pFunc = *(decltype(pFunc))0xFFFFFF;

pFunc is a variable, you can't use it as a type!
Common sense tells me to try this

Your common sense is either broken, or doesn't know C++.
This will compile.
pFunc = reinterpret_cast<void(*)(int,float)>(0xFFFFFF);

I hope you know what you are doing.
closed account (DGvMDjzh)
Thank you for your help. Both solutions work, although peter's is slightly better because I'm not using C++11
Topic archived. No new replies allowed.