Last updated on:February 18, 2023 pm

在跨平台编程中,通过宏来区分不同的平台是一种较为常见的方法。

1 不同平台

1.1 Windows

#ifdef _WIN32
	//is defined for windows (32-bit and 64-bit)
	#ifdef _WIN64
	//windows 64bits
	#else
	//define something for  windows (32-bit only)
#endif

//GUI App
#ifdef _WINDOWS

//CUI App
#ifdef _CONSOLE

//Windows Versions
#ifdef WINVER // or #ifdef _WIN32_WINNT
	#if (WINVER >= 0x030a) //Windows 3.1 and above
	#if (WINVER >= 0x0400) //Windows 95/NT4.0 and above
	#if (WINVER >= 0x0410) //Windows 98 and above
	#if (WINVER >= 0x0500) //Windows Me/2000 and above
	#if (WINVER >= 0x0501) //Windows XP and above
	#if (WINVER >= 0x0600) //Windows Vista and above
	#if (WINVER >= 0x0601) //Windows 7 and above


//DOS
#ifdef __DOS__
#ifdef __MSDOS__

//Cygwin
#ifdef __CYGWIN__

1.2 Unix

//UNIX
#ifdef __unix
#ifdef __unix__

//Linux
#ifdef __linux
#ifdef __linux__

//FreeBSD
#ifdef __FreeBSD__

//NetBSD
#ifdef __NetBSD__

1.3 MacOS & iOS

// Universal
#ifdef __APPLE__
    #include "TargetConditionals.h"
	#if TARGET_IPHONE_SIMULATOR
    	// iOS Simulator
    #elif TARGET_OS_IPHONE
        // iOS device
    #elif TARGET_OS_MAC
        // Other kinds of Mac OS
    #else
        //Unknown Apple platform
    #endif

// Mac OS 9
#ifdef Macintosh

//Mac OS X
#ifdef __APPLE__&&__MACH__

1.4 Android

#ifdef __ANDROID__
	#if __ANDROID_API__ >= 1 //Android Version >= 1.0
	#if __ANDROID_API__ >= 5 //Android Version >= 2.0
	#if __ANDROID_API__ >= 11 //Android Version >= 3.0
	#if __ANDROID_API__ >= 1 //Android Version >= 1.0
	#if __ANDROID_API__ >= 1 //Android Version >= 1.0

2 不同编译器

2.1 GCC

#ifdef __GNUC__
	#if __GNUC__ >= 3 //GCC-3.0 and above

2.2 Visual C++

#ifdef _MSC_VER (非VC编译器很多地方也有定义)
	#if _MSC_VER >= 1000 //MSVC++4.0 and above
	#if _MSC_VER >= 1100 //MSVC++5.0 and above
	#if _MSC_VER >= 1200 //MSVC++6.0 and above
	#if _MSC_VER >= 1300 //MSVC++7.0 and above
	#if _MSC_VER >= 1400 //MSVC++8.0 and above
	#if _MSC_VER >= 1500 //MSVC++9.0 (Visual Studio 2008) and above
	#if _MSC_VER >= 1600 //MSVC++10.0 (Visual Studio 2010) and above
	#if _MSC_VER >= 1700 //MSVC++11.0 (Visual Studio 2012) and above
	#if _MSC_VER >= 1800 //MSVC++12.0 (Visual Studio 2013) and above
	#if _MSC_VER >= 1900 //MSVC++14.0 (Visual Studio 2015) and above
	#if _MSC_VER >= 1910 //MSVC++14.1 (Visual Studio 2017) and above

2.3 Borland C++

#ifdef __BORLANDC__

2.4 CLANG

#ifdef

3 其它

todo


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!

Linux磁盘分区扩容 Previous
【渗透】meterpreter命令详解 Next

 TOC

载入天数... 载入时分秒...