[转载自:http://www.cppblog.com/mzty/archive/2006/12/07/16101.html]
主要是两个问题:指针截断和数据对齐。
C/C++移植的问题
1 新的数据类型和函数
1)固定精度:(跟X86或X64无关)
Term | Description |
---|---|
DWORD32 | 32-bit unsigned integer |
DWORD64 | 64-bit unsigned integer |
INT32 | 32-bit signed integer |
INT64 | 64-bit signed integer |
LONG32 | 32-bit signed integer |
LONG64 | 64-bit signed integer |
UINT32 | Unsigned INT32 |
UINT64 | Unsigned INT64 |
ULONG32 | Unsigned LONG32 |
ULONG64 | Unsigned LONG64 |
Term | Description |
---|---|
DWORD_PTR | Unsigned long type for pointer precision. |
HALF_PTR | Half the size of a pointer. Use within a structure that contains a pointer and two small fields. |
INT_PTR | Signed integer type for pointer precision. |
LONG_PTR | Signed long type for pointer precision. |
SIZE_T | The maximum number of bytes to which a pointer can refer. Use for a count that must span the full range of a pointer. |
SSIZE_T | Signed SIZE_T. |
UHALF_PTR | Unsigned HALF_PTR. |
UINT_PTR | Unsigned INT_PTR. |
ULONG_PTR | Unsigned LONG_PTR. |
Term | Description |
---|---|
POINTER_32 | A 32-bit pointer. On 32-bit Windows, this is a native pointer. On 64-bit Windows, this is a truncated 64-bit pointer. |
POINTER_64 | A 64-bit pointer. On 64-bit Windows, this is a native pointer. On 32-bit Windows, this is a sign-extended 32-bit pointer. Note that it is not safe to assume the state of the high pointer bit. |
[MSDN]An int and a long are 32-bit values on 64-bit Windows operating systems. For programs that you plan to compile for 64-bit platforms, you should be careful not to assign pointers to 32-bit variables. Pointers are 64-bit on 64-bit platforms, and you will truncate the pointer value if you assign it to a 32-bit variable.
在以前的32位系统中,指针的为32位,在新的64位系统中指针为64位,这样的话,我们以前编 程中常用的指针与int或long等的直接转化,放在新的64位的系统中就会出错,指针高位的值就会丢失,从而产生错误。例如下面的2行代码,在32位上 正确,但是在64位上就会发生指针截断,出现错误: