![](/img/trans.png)
[英]Why include direct.h or sys/stat.h conditionally based on _WIN32 or __linux__?
[英]How _WIN32, __linux__… preprocessor macro work?
像 GCC 這樣的 C 編譯器如何定義預處理器宏來檢測當前操作系統?
我查看了 GCC 的源代碼,發現了這個builtin_define ("_WIN32");
但我不確定這是否是定義宏的地方。
TL;DR:基本上,是的。 內置宏在目標描述 header 文件中定義。
經常有一本精美的手冊可供閱讀; 在這種情況下,它是GCC 內部手冊。 (具體來說,在Run-time target specification部分,但不要從那里開始閱讀;你需要一些上下文。)
如果您需要更多信息,請參閱 GCC 文檔的完整綱要。 (內部文檔位於該頁面的底部。)
(If you're comfortable using the GNU info reader and you're using a Ubuntu/Debian system, you can install the GCC documentation for your current GCC version with sudo apt-get install gcc-doc
; that includes the GCC internals documentation. )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.