quote: In theory, you could also use reinterpret_cast to cast pointers to ints and ints to pointers, but this is considered erroneous programming, because on many platforms (especially 64-bit platforms) pointers and ints are of different sizes. For example, on a 64-bit platform, pointers are 64 bit, but integers could be 32 bit. Casting a 64-bit pointer to a 32-bit integer will result in losing 32 critical bits! [-found in "Professional C++ 3rd edition Marc Gregoire"-] |
Would (u)intptr_t fall under the category of ints below? |
I sometimes see (u)intptr_t defined as "typedef (un)signed long (u)intptr_t", and since (un)signed long appears to be 32 bits, would it be proper to use (u)intptr_t in these cases? |
In addition, I don't know what alternatives there are for storing hex literal address. |
(u)intptr_t anAddress = 0x1234'5678'90AB'CDEF;
(u)intptr_t anAddress = reinterpret_cast<(u)intptr_t>(&aLvalue);