可视化C++条件调试
Visual C++ conditional debugging
我正在尝试设置一个带有条件调试的项目。我想要的是有一个宏debug
,当我在调试模式下运行时,它 #defined 到某种 printf/cout/任何东西,而在生产模式下运行时 #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
的定义来自哪里。在正确的设置中,它应该来自/不是来自您的 MSVC 项目,而不是来自其他任何地方。 在这种情况下,根据构建类型,您将拥有所期望的。
很可能您在自己的代码或包含的标头之一中的某个位置定义了它。
您的帖子中没有足够的信息来推断_DEBUG
的真正起源。
在调试模式下,来自 MSVC 的定义将如下所示:
#define _DEBUG
这意味着即使在 DEBUG 构建中,您也不应该看到任何内容。看到输出后,这意味着 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
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 当回溯以零开始时,如何调试崩溃
- 在没有太多条件句的情况下,我如何避免被零除
- 基于多个条件处理地图中的所有元素
- 条件constexpr函数
- 无论条件是否为true,if总是在c++中执行
- 我可以使用条件运算符初始化C风格的字符串文字吗
- 基于模板值的条件变量
- 在linux上调试巨大的C++项目
- 为什么使用__LINE_的代码在发布模式下在MSVC下编译,而不是在调试模式下
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 正在VS调试器中监视映射条目
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 使用调试/崩溃报告将应用程序部署到客户端
- VC++本机单元测试,找不到调试符号
- 条件断点失败的 GDB 特征调试
- 可视化C++条件调试
- 是否有一种方法可以将一个条件设置为gdb中的所有断点,用于调试Cpp代码
- 如何将所有抛出转换为中止条件以进行调试
- 在 Linux 上C++ - 如何 #define #ifdef/#endif 调试条件