Original Post
When I was reading the article on 64-bit errors, it got me thinking about ptrdiff_t. On a 32-bit system, ptrdiff_t is a 32 bit signed integer, meaning one bit is dedicated to the sign, while all 32 bits in a pointer are used when addressing. Thus, one could create erroneous results by subtracting pointers to memory more than 2GB apart.
On a 32-bit system, you get a negative difference. Theoretically, it is possible to get the same issue on a 64-bit system, but you would need over 8EB (that's exabytes) of RAM.
So, why is it safe to use ptrdiff_t for this purpose at all? It seems extremely dangerous to me. All the system has to do is allocate you memory over 2GB apart!
int* temp = (int*)1;int* temp2 = (int*)0xFFFFFFF1;ptrdiff_t diff = temp2 - temp;cout << "ptr diff: " << diff << endl;On a 32-bit system, you get a negative difference. Theoretically, it is possible to get the same issue on a 64-bit system, but you would need over 8EB (that's exabytes) of RAM.
So, why is it safe to use ptrdiff_t for this purpose at all? It seems extremely dangerous to me. All the system has to do is allocate you memory over 2GB apart!