[Info-vax] problem with 64-bit pointers in C
Joukj
joukj at hrem.nano.tudelft.nl
Wed Jan 31 06:30:38 EST 2018
Jan-Erik Soderholm wrote:
> 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
>
>
This implicates that when compiling with 64-bit pointers you always get
a warning when subtracting pointers with DECC. How can you avoid the
warning!
Jouk
More information about the Info-vax
mailing list