如何找到 Microsoft Visual C++ 中使用的编译预处理器
How to find compilation preprocessor used in Microsoft Visual C++
有没有办法找出 C++ 代码中的预处理器,例如NDebug、NOMAXMIN 等?
我可以做类似的事情
#ifdef _DEBUG
std::cout << "in debug mode";
#else
std::cout << "in release mode";
#endif
不过预处理器太多了,同事也可以自己定义一下。
我正在使用 Microsoft Visual Studio 编写 C++ 代码,而不是 gcc。
Visual Studio 自动定义 _DEBUG
,所以我建议你使用那个。
但是,对于便携式解决方案,请使用 NDEBUG
,如下所示:
#ifdef NDEBUG
// nondebug
#else
// debug code
#endif
参考文献:
- Predefined Macros Msdn
- Automatic #defines according to Debug/Release config in Visual Studio 2010
- C / C++ : Portable way to detect debug / release?
PS: 没有自动检测同事定义的 custom 宏的含义的方法,因为同事几乎可以做任何事情。
有没有办法找出 C++ 代码中的预处理器,例如NDebug、NOMAXMIN 等?
我可以做类似的事情
#ifdef _DEBUG
std::cout << "in debug mode";
#else
std::cout << "in release mode";
#endif
不过预处理器太多了,同事也可以自己定义一下。
我正在使用 Microsoft Visual Studio 编写 C++ 代码,而不是 gcc。
Visual Studio 自动定义 _DEBUG
,所以我建议你使用那个。
但是,对于便携式解决方案,请使用 NDEBUG
,如下所示:
#ifdef NDEBUG
// nondebug
#else
// debug code
#endif
参考文献:
- Predefined Macros Msdn
- Automatic #defines according to Debug/Release config in Visual Studio 2010
- C / C++ : Portable way to detect debug / release?
PS: 没有自动检测同事定义的 custom 宏的含义的方法,因为同事几乎可以做任何事情。