VC编译器一个坑:_WIN32宏
VC的编译器下,有好几个OS子系统宏,分别是:
WIN32/_WIN32/WIN64/_WIN64
其中WIN32是在windows.h中定义的
WIN64/_WIN64宏通常是通过工程文件配置预定义宏开关完成
其中_WIN32这个宏最特殊,属于没有定义会被强制定义,所有32位系统、64位系统下均有此宏定义
比如64位工程,编译时指定了WIN64/_WIN64,其实编译时会有三个宏
_WIN32/WIN64/_WIN64
因此,在区分OS类别时,则通常应该如此定义:
#if (defined _WIN64 || defined WIN64 || defined _WIN32 || defined WIN32 || defined WINCE)
#elif (defined ANDROID)
#else
#endif
区分64位的WINDOWS与32位,只能如此定义:
#if (defined _WIN64 || defined WIN64)
#elif (defined _WIN32 || defined WIN32)
#else
#endif
极容易踩到这个坑,定义这样:
#if (defined _WIN32 || defined WIN32)
#elif (defined _WIN64 || defined WIN64)
#else
#endif