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

John E. Malmberg wb8tyw at qsl.net_work
Fri Sep 13 09:32:48 EDT 2019


On 9/12/2019 9:06 AM, John Reagan wrote:
> 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);
> 
> }

Your code is the effectively the same as mine.

It seems to work well when all the code is in the same module.

In my actual library that uses this same code it is failing by producing 
a negative 32 bit pointer for these values.

So I am trying to figure out what I am doing wrong.

 >> str64 = 2060834088 or 0x000000007ad5d528
 >> str32 = -2147483536 or 0x80000070

It looks like the compiler is generating different code when everything 
is in one source compilation then when the source pointer is from a 
separately compiled module and destination pointer to be updated is 
passed by address from the same separately compiled module.

If I cast the result from the masked 64 bit pointer to an unsigned, I 
get the correct number.

When I then try to put that unsigned number in a 32 bit char pointer, I 
get a negative address.

Everything I have tried so far in the actual code results in a negative 
32 bit pointer being saved.

I can not reproduce it in an example that only uses one compilation 
module.  In a single compilation I get the correct 32 bit pointer value 
returned.

Regards.
-John



More information about the Info-vax mailing list