添加监视显示未定义的标识符 Visual Studio 2012,cpp [英] add watch shows undefined identifier visual studio 2012, cpp

查看:82
本文介绍了添加监视显示未定义的标识符 Visual Studio 2012,cpp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS 2012 中遇到了最奇怪的行为(我用 cpp 编写).

I encounter the strangest behavior in VS 2012 (I'm writing in cpp).

我在一个变量上单击添加监视",它显示标识符未定义".

I click "add watch" on a variable and it says "identifier is undefined".

以下是代码示例:

for (int j=0;j<32;j++)
        {
            unsigned char curValue=desc1.at<unsigned char>(0,j);
            printf("%s\n",curValue);    
        }

我不得不使用 printf 来显示 curValue 的值.哈哈.

I had to use printf to show the value of curValue. lol.

有人遇到过这种行为吗?

Has anyone encountered such behavior?

更奇怪的是这种情况发生.调试以下代码时:

more strange this occur. When debugging the following code:

    int b1[8];

    for (int k=0;k<7;k++)
        b1[k]=0;

    char q=curValue; 
    int t=0;
    while (q!=0){
        b1[t++]=q%2;
        q=q/2;
    }

调试器只是跳过 b1[k]=0 的循环;

The debugger just skips the loop with b1[k]=0;

请注意,即使在循环内部,curValue 也是未定义的.

Please note curValue is undefined even inside the loop.

谢谢!

推荐答案

正如 Joachim 所说:curValue 是在循环内部定义的.如果 Visual Studio 中的监视窗口将其视为未定义值,则应关闭编译器优化.

As Joachim said: curValue is defined inside the loop. If watch window in visual studio see it as undefined value then you should turn off Compiler optimization.

编译器优化默认为/O2 优化速度.关闭它:

Compiler optimization default is /O2 optimize for speed. To turn it off :

  • 转到项目,右键单击并选择属性
  • 配置属性->C/C++->优化
  • 选择 optimization ,并将其从 Maximize Speed (/O2) 更改为 Disabled (/Od)

这篇关于添加监视显示未定义的标识符 Visual Studio 2012,cpp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆