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

Arne Vajhøj arne at vajhoej.dk
Thu Sep 12 12:13:35 EDT 2019


On 9/12/2019 9:45 AM, 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?

I would just do a simple case.

#include <stdio.h>

#pragma pointer_size 64
typedef char *char_ptr64;

#pragma pointer_size 32
typedef char *char_ptr32;

int main(int argc,char *argv[])
{
    char_ptr64 str64;
    char_ptr32 str32;
    printf("%d %d\n", (int)sizeof(str64), (int)sizeof(str32));
    str64 = (char_ptr64)0x000000007AD5D528LL;
    str32 = (char_ptr32)str64;
    printf("%016llX %08X\n", str64, str32);
    if(str64 != str32)
    {
       printf("Houston we have a problem\n");
       return 0;
    }
    str64 = (char_ptr64)0x000000017AD5D528LL;
    str32 = (char_ptr32)str64;
    printf("%016llX %08X\n", str64, str32);
    if(str64 != str32)
    {
       printf("Houston we have a problem\n");
       return 0;
    }
    return 0;
}

produce what I expect:

8 4
000000007AD5D528 7AD5D528
000000017AD5D528 7AD5D528
Houston we have a problem

Arne






More information about the Info-vax mailing list