[Info-vax] DEC C 64/32 bit pointer conversion question

Bob Gezelter gezelter at rlgsc.com
Thu Sep 12 10:09:47 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

John,

I do not have my OpenVMS system handy at the moment.

Perhaps use a union along the lines of:

union {
          char * ptr64;
          unsigned long twoint[2];
          }

With a safety check that the high 32 bits are as expected.

- Bob Gezelter, http://www.rlgsc.com



More information about the Info-vax mailing list