64

All posts tagged 64

最近在折腾将系统升级成64位。

目前主要碰到两个问题:

(1) 指针和整形转换的问题

(2)long,unsigned long在32位下为32位,在64位下为64位。

对于1,应该采用intptr_t或者uintptr_t。

我采用了luajit的声明(呵呵,作者的注释很有趣):

#if defined(_MSC_VER)
/* MSVC is stuck in the last century and doesn’t have C99’s stdint.h. */
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#ifdef _WIN64
typedef __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else
typedef __int32 intptr_t;
typedef unsigned __int32 uintptr_t;
#endif
#elif defined(__symbian__)
/* Cough. */
typedef signed char int8_t;
typedef short int int16_t;
typedef int int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long long uint64_t;
typedef int intptr_t;
typedef unsigned int uintptr_t;
#else
#include <stdint.h>
#endif

对于2,用int或者unsigned int替换之。

 

后来发现网上这篇文章不错:

http://www.oracle.com/technetwork/cn/server-storage/solaris/ilp32tolp64issues-137107-zhs.html