Guide to predefined macros in C++ compilers (gcc, clang, msvc etc.)

https://blog.kowalczyk.info/article/j/guide-to-predefined-macros-in-c-compilers-gcc-clang-msvc-etc..html

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
复制代码
posted @   Fun_with_Words  阅读(35)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 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++写的推箱子搜索,速度超快









 和6张牌。

点击右上角即可分享
微信分享提示