I want to reinterpret cast a function pointer into a void* variable. The type of the function pointer will be of type Class* (*)(void*)
.
Below is the sample code,
class Test
{
int a;
};
int main()
{
Test* *p(void **a);
void *f=reinterpret_cast<void*>(p);
}
The above code works well with Visual Studio/x86 compilers. But with ARM compiler, it gives compilation error. Don't know why.
Error: #694: reinterpret_cast cannot cast away const or other type qualifiers
I read the explanation in http://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type
I was concerned about the below explanation.
Casting between function pointers and regular pointers (e.g. casting a
void (*)(void)
to avoid*
). Function pointers aren't necessarily the same size as regular pointers, since on some architectures they might contain extra contextual information. This will probably work ok on x86, but remember that it's undefined behavior.
How to do such conversions from void (*)(void*) -> void*
effectively so that atleast it compiles almost the same in most of the compilers ?