I\'m working on a school project that involves porting a large piece of C++ code on an experimental piece of hardware. Unfortunately, that hardware is 64-bit and the code contai
Save this piece of code as mycast.hpp
and add -include mycast.hpp
to your Makefile
.
#include
template
U Reinterpret_cast(T *x) {
return (U)(uintptr_t)x;
}
template
U Reinterpret_cast(T &x) {
return *(U*)&x;
}
#define reinterpret_cast Reinterpret_cast
They should do their job unless your code is too tricky.
Your strategy will not work for stack-allocated objects, be careful!! You can insert some debugging/logging logic to Reinterpret_cast
if necessary.