【发布时间】:2009-12-17 12:02:33
【问题描述】:
我想我知道我需要使用什么 #ifdefs 才能在 msvc 和 gcc 上兼容 x86-32 和 x86-64,见下文。这些平台是否完整?
#if defined(_MSC_VER)
# if defined(_M_IA64) || defined(_M_X64)
# define SIZEOF_SIZE_T 8
# define SIZEOF_VOIDP 8
# elif defined(_M_IX86)
# define SIZEOF_SIZE_T 4
# define SIZEOF_VOIDP 4
# else
# error "Unsupported MSVC platform"
# endif
#elif defined(__GNUG__)
# if defined(__x86_64__) || defined(__ia64__)
# define SIZEOF_SIZE_T 8
# define SIZEOF_VOIDP 8
# elif defined(__i386__)
# define SIZEOF_SIZE_T 4
# define SIZEOF_VOIDP 4
# else
# error "Unsupported GCC platform"
# endif
#endif
从 C 程序员的角度来看,IA64 和 x86 64 是否相同?
我还希望能够在 Mac 上编译。我要添加什么?
编辑:我不能使用 sizeof(),因为我正在处理使用像 #if SIZEOF_VOIDP == SIZEOF_LONG 这样的东西的不可触碰的遗留代码。我也只对架构感兴趣,而不是实际内容。注意预编译器不允许#if sizeof(size_t) == sizeof(void*)。
【问题讨论】:
-
当
sizeof (void*)也是编译时间常数时,为什么要#defining 常量? -
需要预编译时间常数。
-
完整,因为我涵盖了这两种架构。还想添加 Mac 架构,无论是哪一种。
-
我不明白你为什么不能做
#define SIZEOF_LONG sizeof(long)? -
预编译器不允许#if sizeof(whatever) == sizeof(other)。
标签: c 64-bit portability itanium