I need to represent pointers as strings for the user. Sometimes the values can be saved to a file and transferred to a computer with a different architecture (32 vs 64 bit - the main problem at present) and loaded from a text file for comparison - I'm going to compare only the downloaded values with each other, but I still prefer compare numbers than strings.
I am currently using:
SomeClass* p;
...
printf("%ld", (uintptr_t)p);
but I wonder if it is portable (only Windows and Linux are important at this stage), and will it be interrupted after the advent of 128-bit systems?
Edit : if I didn’t decide to use uint64_t and decided that it was a 64-bit roof, this cannot be done because some kind of 64-bit pointer might be outside the 32-bit integer range. So, I decided that it would be safer to compare strings, even if they are slower.
source
share