[Info-vax] problem with 64-bit pointers in C
Joukj
joukj at hrem.nano.tudelft.nl
Wed Jan 31 07:40:09 EST 2018
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>
The reason for asking this question is that I tried to compile the
pnglib package with 64 bit pointers. It compiled with some warnings and
the self-test failed. So I'm trying to reduce the compile warnings first.
regards
Jouk
More information about the Info-vax
mailing list