[英]Visual C++ conditional debugging
我正在尝试使用条件调试来设置项目。 我想要的是进行宏debug
,在调试模式下运行时将其定义为某种printf / cout /任何内容,而在生产模式下运行时则将其定义为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
来自何处。 在正确的设置中,它应该来自/不来自您的MSVC项目以及其他任何地方。 在这种情况下,根据构建类型,您将获得期望的结果。
您很可能在自己的代码中或包含的标头之一中定义了它。
您的帖子中没有足够的信息来推断_DEBUG
的真实来源。
在调试模式下,来自MSVC的定义如下所示:
#define _DEBUG
这意味着即使在调试版本中,您也不会看到任何内容。 看到输出后,这意味着defn存在并且不为空。 此defn并非来自MSVC。
尝试这个
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
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.