不同系統宏定義

#ifdef _WIN32
   //define something for Windows (32-bit and 64-bit, this part is common)
   #ifdef _WIN64
      //define something for Windows (64-bit only)
   #else
      //define something for Windows (32-bit only)
   #endif
#elif __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
    #   error "Unknown Apple platform"
    #endif
#elif __linux__
    // linux
#elif __unix__ // all unices not caught above
    // Unix
#elif defined(_POSIX_VERSION)
    // POSIX
#else
#   error "Unknown compiler"
#endif

值得注意的是1. _WIN32包含了windows 32和64bit,_WIN64纔是windows 64bit。

2. 蘋果系統都定義了__APPLE__,TARGET_OS_MAC包含了TARGET_OS_IPHONE,而TARGET_OS_IPHONE又包含了TARGET_IPHONE_SIMULATOR

 

參考來源:

1. how-do-i-check-os-with-a-preprocessor-directive

2. how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor

3. apple TargetConditionals.h

發佈了60 篇原創文章 · 獲贊 638 · 訪問量 51萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章