[Info-vax] DEC C 64/32 bit pointer conversion question
John Reagan
xyzzy1959 at gmail.com
Thu Sep 12 10:06:11 EDT 2019
On Thursday, September 12, 2019 at 9:45:46 AM UTC-4, John E. Malmberg wrote:
> I have a case where a system service only has accepts a 32 bit pointer
> in an item list.
>
> When I am compiling with 64 bit pointers available and the value can be
> referenced in a 32 bit pointer, I would like to just extract out the
> lower 32 bits.
>
> However on the test program I get:
>
> #if __INITIAL_POINTER_SIZE == 64
> # pragma pointer_size save
> # pragma pointer_size 32
> #endif
>
> #ifndef VMS_PTR32_TYPEDEF
> #define VMS_PTR32_TYPEDEF
>
> typedef char * char_ptr32;
> typedef unsigned long * long_ptr32;
> typedef void * void_ptr32;
>
> #endif
>
>
>
> str32 = (char_ptr32)((unsigned long int)str_64 & 0xFFFFFFFF);
>
> str64 = 2060834088 or 0x000000007ad5d528
> str32 = -2147483536 or 0x80000070
>
> Which of course does not work.
>
> What am I doing wrong?
>
> Regards,
> -John
#include <stdio.h>
main() {
#pragma pointer_size 64
char * str64;
typedef char * char_ptr64;
#pragma pointer_size 32
char * str32;
typedef char * char_ptr32;
typedef unsigned long * long_ptr32;
typedef void * void_ptr32;
str64 = (char_ptr64) 0x000000007ad5d528ULL;
str32 = (char_ptr32)((unsigned long int)str64 & 0xFFFFFFFF);
printf("str64 = %016llx, str32 = %08lx\n", str64, str32);
}
$ cc /pointer=64 ptr64
$ link ptr64
$ run ptr64
str64 = 000000007ad5d528, str32 = 7ad5d528
You can also do
str32 = str64;
but you will get the MAYLOSEDATA2 warning which you'd have to disable
$ cc /pointer=64 ptr64
str32 = str64;
..........^
%CC-W-MAYLOSEDATA2, In this statement, "str64" has a larger data size than "short pointer to char". Assignment can result in data loss.
at line number 18 in file WORK20:[JREAGAN]PTR64.C;7
More information about the Info-vax
mailing list