[Info-vax] problem with 64-bit pointers in C
Jan-Erik Soderholm
jan-erik.soderholm at telia.com
Wed Jan 31 09:16:32 EST 2018
Den 2018-01-31 kl. 15:15, skrev Jan-Erik Soderholm:
> Den 2018-01-31 kl. 13:40, skrev Joukj:
>> John Reagan wrote:
>>> The largest possible variable is 32-bits big even with 64-bit pointers.
>>>
>>> You can only subtract pointers that point inside the same variable.
>>> Therefore they can never be more than 32-bits apart.
>>
>> So this will not bite me in the application : Although both pointer are
>> 64-bit the difference result should be 32-bit.
>> But still you always get the warning.....
>>
>>>
>>> That's why ptrdiff_t is always 32. The type is built into the frontend
>>> and can't easily be tweaked by header changes.
>>>
>>> You notice that size_t is also 32 even with 64-bit pointers.
>>>
>>> Looking back, better choices could have been made. Going forward, I'd
>>> like to have a real LP64 mode with 'long' being 64 to match compilers
>>> like clang.
>>>
>>> For now, typecast one of them to __int64 at the subtract.
>> When casting one of them I get a a compiler error
>> printf( "%lld\n" , (__int64)buffer - entry_start );
>> ......................^
>> %CC-E-NOSUBTRACT, In this statement, "entry_start" cannot be subtracted
>> from "(6
>> 4 bit int)buffer".
>> at line number 13 in file $DISK6:[JOUKJ.test]test.c;86
>>
>> Type casting both is just the same as I did in the last line of the test
>> and gives you sizeof(int)*<expected result>
>>
>
> This "works" (with a warning):
>
> printf( "%d %d %d\n" , sizeof( entry_start ) ,
> sizeof( (__int64)(entry_start - buffer) ) ,
> sizeof( buffer ) );
>
> It typecasts the *result* of the subtraction, not the individual
> variables. Now, it can still not be a values larger than 32 bits,
> I guess, even if it is later typecasted to 64 bits...)
>
Sorry, forgot...
$ cc /ver
VSI C V7.4-002 on OpenVMS Alpha V8.4-2L2
$
More information about the Info-vax
mailing list