[Info-vax] problem with 64-bit pointers in C

Joukj joukj at hrem.nano.tudelft.nl
Wed Jan 31 05:08:05 EST 2018


ergamenes at gmail.com wrote:
> On Wednesday, 31 January 2018 08:36:25 UTC, Joukj  wrote:
> 
>> Looks like the artthmatic - (and + ) on pointers is not resulting in the 
>> expected 64-bit pointer as it should.
> 
> I can see two problems: one is that subtracting arbitrary pointers is UB, so anything can happen.
The code where it comes from uses this to determine the length a 
data-string. It works OK with 32 bit pointers.

> 
> The other thing is that when it is valid, it gives a result that is of type ptrdiff_t, which here is defined to be an int. That does mean that there is a restriction that you can't have arrays of more than 2^31 elements. 

What I read from the error message is that the subtraction is performed 
in 64 bit but afterwards the result is cast to a int (or prtdiff_t). 
What is the reason for doing this?
If I run my sample program on a 64-bit Linux system I get the expected 
results.

                 Jouk



More information about the Info-vax mailing list