怎么使自定义类型适用于32位或64位平台
如何使自定义类型适用于32位或64位平台
如题。例如在一个头文件中定义:typedef int MyInt;
MyInt 能在win32或者win64下使用;
为了这个头文件能在 32位或64位下使用,编译时候,自动区分MyInt是32位的int还是64位的int
------解决方案--------------------
用条件编译
------解决方案--------------------
首先int和long在VC的32和64位下没有区别,不用在意
如果存在其他有区别的类型,或者在gcc下,得靠编译器提供的内置预处理宏
比如VC的话,你可以用#ifdef _M_X64,这个预处理生效,就是64位编译器
gcc的话,用#ifdef _X86_64_
------解决方案--------------------
是不是说的是条件编译的事儿:
#if (sizeof(int) == 4)
typedef ...
#else
typedef ...
#endif
以上方法没验证过,而且有一部分64位操作系统,似乎int的长度好像也是4来着
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
int long 在64位系统里都是32位,但指针和像sizt_t intptr time_t这些是64位了。
------解决方案--------------------
“适用于32位或64位平台”的定义是什么?
如果只是想获得特定长度的整型,穷举一遍总能找出来,反正整型就那么几个……
------解决方案--------------------
64位分X64和IA64两种
------解决方案--------------------
------解决方案--------------------
Platform SDK: 64-bit Windows Programming
Migration Tips
The two primary areas of concern when examining your code for 64-bit compatibility are as follows:
Address calculations
Pointer arithmetic
For many reasons, developers have stored addresses as a ULONG value. After all, on 32-bit Windows, an address, a pointer, and a ULONG value are all 32 bits long. However, on 64-bit Windows, an address and a ULONG are not the same length. While a ULONG remains a 32-bit value, all pointers are now 64-bit values.
For more information, see the following topics:
General Porting Guidelines
Storing a 64-bit Value
Common Compiler Errors
Additional Considerations
如题。例如在一个头文件中定义:typedef int MyInt;
MyInt 能在win32或者win64下使用;
为了这个头文件能在 32位或64位下使用,编译时候,自动区分MyInt是32位的int还是64位的int
------解决方案--------------------
用条件编译
------解决方案--------------------
首先int和long在VC的32和64位下没有区别,不用在意
如果存在其他有区别的类型,或者在gcc下,得靠编译器提供的内置预处理宏
比如VC的话,你可以用#ifdef _M_X64,这个预处理生效,就是64位编译器
gcc的话,用#ifdef _X86_64_
------解决方案--------------------
是不是说的是条件编译的事儿:
#if (sizeof(int) == 4)
typedef ...
#else
typedef ...
#endif
以上方法没验证过,而且有一部分64位操作系统,似乎int的长度好像也是4来着
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
int long 在64位系统里都是32位,但指针和像sizt_t intptr time_t这些是64位了。
------解决方案--------------------
“适用于32位或64位平台”的定义是什么?
如果只是想获得特定长度的整型,穷举一遍总能找出来,反正整型就那么几个……
------解决方案--------------------
64位分X64和IA64两种
------解决方案--------------------
------解决方案--------------------
Platform SDK: 64-bit Windows Programming
Migration Tips
The two primary areas of concern when examining your code for 64-bit compatibility are as follows:
Address calculations
Pointer arithmetic
For many reasons, developers have stored addresses as a ULONG value. After all, on 32-bit Windows, an address, a pointer, and a ULONG value are all 32 bits long. However, on 64-bit Windows, an address and a ULONG are not the same length. While a ULONG remains a 32-bit value, all pointers are now 64-bit values.
For more information, see the following topics:
General Porting Guidelines
Storing a 64-bit Value
Common Compiler Errors
Additional Considerations