Guide to predefined macros in C++ compilers (gcc, clang, msvc etc.)
When writing portable C++ code you need to write conditional code that depends on compiler used or the OS for which the code is written. To perform those checks you need to check pre-processor macros that various compilers set.
To list gcc’s pre-defined macros: gcc -x c /dev/null -dM -E
The -x c /dev/null -dM -E also works for mingw (which is based on gcc). tdm-gcc不好使,把 /dev/null 换成 nul: 可以。
Option Summary (Using the GNU Compiler Collection (GCC))
- -x language Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix).
- -dM Instead of the normal output, generate a list of ‘#define’ directives for all the macros defined during the execution of the preprocessor, including predefined macros.
- -E Stop after the preprocessing stage; do not run the compiler proper.
... #define __MINGW32__ 1 #define __GNUC__ 10 #define __VERSION__ "10.3.0" #define WINNT 1 #define WIN32 1 // ifdef WIN32和ifdef _WIN32都能用没啥神秘的,因为两个都定义了。按字符算钱的话,还有__WIN32__ #define _WIN32 1 #define __WINNT 1 #define __WINNT__ 1 #define __WIN32__ 1 ... #define __WCHAR_WIDTH__ 16 #define __WCHAR_MAX__ 0xffff ... #define __declspec(x) __attribute__((x)) ... #define __INT64_C(c) c ## LL #define __UINT64_C(c) c ## ULL
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
2021-12-18 AI vs. Machine Learning vs. Deep Learning vs. Neural Networks: What's the Difference?
2021-12-18 Automate Debugging with GDB Python API
2021-12-18 What is deep learning?
2021-12-18 非线性回归和偏微分
2021-12-18 STL的set有test_and_set功能
2021-12-18 JS实现粘贴上传图片原理
2021-12-18 C++写的推箱子搜索,速度超快