【发布时间】:2012-10-12 18:27:13
【问题描述】:
我正在尝试设置一个带有条件调试的项目。我想要的是有一个宏debug,当我在调试模式下运行时,它被#defined 到某种 printf/cout/anything,而在生产模式下运行时,#defined 到 null 语句。我该怎么做:
我尝试使用宏 _DEBUG,但无论我在哪种模式下运行,我总是看到我的参数打印:
struct debugger{template<typename T> debugger& operator ,(const T& v){std::cerr<<v<<" ";return *this;}}dbg;
#if _DEBUG
#define debug(...) {dbg,__VA_ARGS__;std::cerr<<std::endl;}
#else
#define debug(...) // Just strip off all debug tokens
#endif
在我的主要:
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int a=1,b=2,c=3;
debug(a,b,c);
cin>>a;
}
如果有帮助,我正在使用 Visual Studio 2012
【问题讨论】:
-
你是如何尝试
_DEBUG的?你也可以试试OutputDebugString。 -
#if defined _DEBUG?或标准的#ifndef NDEBUG -
顺便说一句,
_DEBUG确定您要链接的 CRT,而不是编译是否调试。使用 NDEBUG 并正确定义它。 -
您确定在构建 Release 版本时将配置设置为 Release?
-
@ybungalobill 这完全不正确。 _DEBUG does 表示配置是Debug 还是Release。我认为 VC++ 根本不使用 NDEBUG。
标签: c++ visual-studio debugging c-preprocessor conditional-compilation