我想我知道我需要使用什么#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*)
.