I'm trying to cast a pointer to an int (or unsigned int) and no matter what I try it doesn't want to work.
I've tried static_cast<intptr_t>(obj)
, reinterpret_cast<intptr_t>(obj)
, and various combinations of C style casts, intptr_t
's, unsigned int
's, and I'm including stdint.h. From what I've read, one of the many things I've tried should work. What gives?
I didn't bother including the code because it's exactly what I described, but since you asked, I've tried all of these plus other combinations:
void myfunc(Foo* obj)
{
// ...
uintptr_t temp = reinterpret_cast<uintptr_t>(obj);
uintptr_t temp = static_cast<uintptr_t>(obj);
uintptr_t temp = (uintptr_t)obj;
intptr_t temp = reinterpret_cast<intptr_t>(obj);
intptr_t temp = static_cast<intptr_t>(obj);
intptr_t temp = (intptr_t)obj;
unsigned int temp = reinterpret_cast<unsigned int>(obj);
unsigned int temp = static_cast<unsigned int>(obj);
unsigned int temp = (unsigned int)obj;
// ...
}
They all give the exact same error.