moving a structure from 32-bit to 64-bit in C programming language [closed]

风格不统一 提交于 2019-12-02 10:02:14

You can copy data just fine between 32-bit and 64-bit, provided you use compatible data types.

For example, the structure:

struct xyzzy {
    int a;
    int b;
}

won't be compatible if your int types are of different widths in the 32-bit and 64-bit world.

C99 provided fixed width types such as int32_t which are meant to be the same size regardless of platform. If your compiler is compliant, it is required to provide those types if it has an actual type of that size.

Failing that, you can often change your source code so that these problems are minimised, such as with:

#ifdef INT_IS_64BITS
    typedef int my_64bit_type;
#endif

#ifdef LONG_IS_64BITS
    typedef long my_64bit_type;
#endif

my_64bit_type xyzzy;

and compile with a suitable definition:

gcc -DLONG_IS_64BITS myprog.c
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!