[Info-vax] problem with 64-bit pointers in C
Jan-Erik Soderholm
jan-erik.soderholm at telia.com
Wed Jan 31 05:28:34 EST 2018
Den 2018-01-31 kl. 11:08, skrev Joukj:
> 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
http://www.gnu.org/software/libc/manual/html_node/Important-Data-Types.html
More information about the Info-vax
mailing list