This is exactly the same question title as found here – I would also like to store a memory address in a variable – or rather, a void* in a variable. However, I’d rather store it in some form of an int rather than a string, as I’d like to cast it back to a pointer afterwards.
This is because it is a member of a class that I would then like to serialize with boost serialize, and if I did use a void*, boost serialize might try to store what the pointer is pointing to, which wouldn’t be very sensible in my case.
I need this for 32 and 64 bit gcc and MSVC, so basically I was wondering whether there was an inbuilt integer type that was the size of pointers on the same platform. Alternatively, I guess I would need to IFDEF my own type?
intptr_tanduintptr_tare integer types that are large enough to hold avoid*. They are defined by C++11 in<cstdint>and by C99 in<stdint.h>If
uintptr_tis not available, you could tryuintmax_t, defined in the same header(s) or by Boost in<boost/cstdint.hpp>.