Is casting a function pointer to int then casting it back and making an indirect call an undefined behavior in C++? Like this:
void f()
{
puts("Hello\n");
}
int pf = (int)f;
//...some time later
typedef void (*PVoidFunc)();
(*(PVoidFunc)pf)();
Assume that int and pointer are the same size.
EDIT: The architecture is 32-bit - it's vanilla Android.
It's important, though, that we're talking function pointers, not data pointers. The underlying issue has to do with the way Thumb functions have two addresses - their true starting address (2-aligned) and the value you need to BLX to (address OR 1). I think GCC is trying to be smart about that, but it comes out rather bogus.
Naturally, the issue is that this doesn't work for me in one particular case, but works in a very similar one :) But I'm wondering if this is a compiler bug, compiler's attempt to work around the thorny underlying problem, or undefined behavior being undefined.