编码的时候经常要用到条件编译
编译器
GCC #ifdef __GNUC__ #if __GNUC__ >= 3 // GCC3.0以上 Visual C++ #ifdef _MSC_VER(非VC编译器很多地方也有定义) #if _MSC_VER >=1000 // VC++4.0以上 #if _MSC_VER >=1100 // VC++5.0以上 #if _MSC_VER >=1200 // VC++6.0以上 #if _MSC_VER >=1300 // VC2003以上 #if _MSC_VER >=1400 // VC2005以上 Borland C++ #ifdef __BORLANDC__
操作系统
UNIX #ifdef __unix or #ifdef __unix__ Linux #ifdef __linux or #ifdef __linux__ FreeBSD #ifdef __FreeBSD__ NetBSD #ifdef __NetBSD__
Windows 32bit #ifdef _WIN32(或者WIN32) 64bit #ifdef _WIN64 GUI App #ifdef _WINDOWS CUI App #ifdef _CONSOLE
Windows的Ver … WINVER ※ PC机Windows(95/98/Me/NT/2000/XP/Vista)和Windows CE都定义了 #if (WINVER >= 0x030a) // Windows 3.1以上 #if (WINVER >= 0x0400) // Windows 95/NT4.0以上 #if (WINVER >= 0x0410) // Windows 98以上 #if (WINVER >= 0x0500) // Windows Me/2000以上 #if (WINVER >= 0x0501) // Windows XP以上 #if (WINVER >= 0x0600) // Windows Vista以上 Windows 95/98/Me的Ver … _WIN32_WINDOWS MFC App、PC机上(Windows CE没有定义) #ifdef _WIN32_WINDOWS #if (_WIN32_WINDOWS >= 0x0400) // Windows 95以上 #if (_WIN32_WINDOWS >= 0x0410) // Windows 98以上 #if (_WIN32_WINDOWS >= 0x0500) // Windows Me以上 Windows NT的Ver … _WIN32_WINNT #if (_WIN32_WINNT >= 0x0500) // Windows 2000以上 #if (_WIN32_WINNT >= 0x0501) // Windows XP以上 #if (_WIN32_WINNT >= 0x0600) // Windows Vista以上 Windows CE(PocketPC) #ifdef _WIN32_WCE Windows CE … WINCEOSVER Windows CE WCE_IF Internet Explorer的Ver … _WIN32_IE
Cygwin #ifdef __CYGWIN__ 32bit版Cygwin(现在好像还没有64bit版) #ifdef __CYGWIN32__ MinGW(-mno-cygwin指定) #ifdef __MINGW32__