久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 C 預處理器中可靠地檢測 Mac OS X、iOS、L

How to detect reliably Mac OS X, iOS, Linux, Windows in C preprocessor?(如何在 C 預處理器中可靠地檢測 Mac OS X、iOS、Linux、Windows?)
本文介紹了如何在 C 預處理器中可靠地檢測 Mac OS X、iOS、Linux、Windows?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果有一些跨平臺的 C/C++ 代碼應該在 Mac OS X、iOS、Linux、Windows 上編譯,我如何在預處理過程中可靠地檢測它們?

If there's some cross-platform C/C++ code that should be compiled on Mac OS X, iOS, Linux, Windows, how can I detect them reliably during preprocessor process?

推薦答案

有大多數編譯器使用的預定義宏,你可以找到列表 此處.GCC 編譯器預定義宏可以在此處找到.以下是 gcc 的示例:

There are predefined macros that are used by most compilers, you can find the list here. GCC compiler predefined macros can be found here. Here is an example for gcc:

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
   //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
    #if TARGET_OS_MACCATALYST
         // Mac's Catalyst (ports iOS API into Mac, like UIKit).
    #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

定義的宏取決于您要使用的編譯器.

The defined macros depend on the compiler that you are going to use.

_WIN64 #ifdef 可以嵌套到_WIN32 #ifdef 因為_WIN32code> 甚至在面向 Windows x64 版本時定義.如果某些標頭包含對兩者通用,則這可以防止代碼重復(也WIN32 沒有下劃線允許IDE 突出顯示代碼的正確分區).

The _WIN64 #ifdef can be nested into the _WIN32 #ifdef because _WIN32 is even defined when targeting the Windows x64 version. This prevents code duplication if some header includes are common to both (also WIN32 without underscore allows IDE to highlight the right partition of code).

這篇關于如何在 C 預處理器中可靠地檢測 Mac OS X、iOS、Linux、Windows?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉換為 HSV 并將 HSV 轉換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉換為字符串?)
When to use inline function and when not to use it?(什么時候使用內聯函數,什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);)
Is TCHAR still relevant?(TCHAR 仍然相關嗎?)
主站蜘蛛池模板: 欧美色专区 | 玖玖视频网 | 国产亚洲一区精品 | 亚洲福利在线观看 | 美女久久久久 | 日韩欧美在线播放 | 中文字幕一区二区不卡 | 国产视频久久 | 福利视频一二区 | 成人影院在线视频 | 成人av播放 | 日本久久久一区二区三区 | 剑来高清在线观看 | 激情视频网站 | 国产区一区二区三区 | 欧美日韩亚洲系列 | 精品视频在线一区 | 天天天天操 | 99热视| 中文字幕一区二区三区乱码图片 | 久久久久久久久中文字幕 | 欧美色999| 久久精品国产v日韩v亚洲 | 九九热精品免费 | 精品国产免费一区二区三区演员表 | 亚洲国产精品99久久久久久久久 | 精国产品一区二区三区四季综 | 久久狠狠 | www.久久.com | 久久亚洲天堂 | 91精品国产高清一区二区三区 | 国产精品视频免费播放 | 婷婷激情综合 | 久久国产精品久久久久 | 亚洲视频在线观看免费 | 日韩欧美一区在线 | 二区视频| 国产激情一区二区三区 | 欧美久久一区二区 | www.亚洲国产精品 | 国产一区久久久 |