Porting Legacy code to 64 Bit in C++

时间:2021-10-30 12:14:47

I am trying to port a legacy 32 bit code to 64 bit. In that we have a union like this:

我试图将传统的32位代码移植到64位。因为我们有这样一个联盟:

union ptType
{
    int * iPtr;
    short * sPtr;
    long * lPtr;
    bool * bPtr;
    double * dPtr;
};

As you can guess, this union is used to store addresses of all these types. I have read about a lot pointer size and arithmetic changing in 64 bit. But am not too sure of this behavior. This code seems to work in QA, but I am more apprehensive about production as it would enormous traffic there.

您可以猜到,此联合用于存储所有这些类型的地址。我已经阅读了很多指针大小和64位算术变化。但我不太确定这种行为。这段代码似乎在质量保证中起作用,但我对生产更加担心,因为它会产生巨大的流量。

How will porting to 64 bit affect the behavior of the code?

如何移植到64位会影响代码的行为?

1 个解决方案

#1


3  

You're right that under most 32- to 64-bit transitions, those pointers will all double in size. The operation of this union itself is unlikely to be a problem, but you'll have to look out for places where it interacts with other code, via typecasts, hardcoded sizes, etc.

你说得对,在大多数32到64位转换下,这些指针的大小都会加倍。这个联合本身的操作不太可能是一个问题,但你必须通过类型转换,硬编码大小等来寻找与其他代码交互的地方。

#1


3  

You're right that under most 32- to 64-bit transitions, those pointers will all double in size. The operation of this union itself is unlikely to be a problem, but you'll have to look out for places where it interacts with other code, via typecasts, hardcoded sizes, etc.

你说得对,在大多数32到64位转换下,这些指针的大小都会加倍。这个联合本身的操作不太可能是一个问题,但你必须通过类型转换,硬编码大小等来寻找与其他代码交互的地方。