积极答复者
[VS2012bug]调试时,全局变量的值显示不正确,但printf出来的值正常

问题
-
如图所示,g_Port是我再一个头文件定义的全局静态变量:
static int g_Port = -1;
在一个当前类的静态函数中对他进行赋值:
g_Port = 100; //atoi(port);
printf("g_Port=%d\n", g_Port);结果调试工具显示没有变化,但打印出来是变化了的,这个bug我觉的非常严重,因为之前我的其他工程也遇到过类似的问题,我以为是我代码有bug,耗费了很长时间去调试自己的代码。希望微软尽快修复。
这个bug不是必现的,但在我的环境中确实存在,我把我的环境描述下:
VS2012 具体版本是:11.0.60610.01 update3
程序编译模式是:x64 debug
操作系统是:Win7 x64 英文旗舰版
答案
-
请在Watch/Autos窗口中观察,如下图所示:
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
-
你好:
根据你的描述,为了你的问题能过得到更好的解决,我把你的问题提到了connect上,在connect上会有对这个产品比较熟悉的人来参与你的问题。
下面是你问题的英文描述:
The steps to repro as below:
1, assign a static global variable g_Port as -1
2, change the value g_Port from -1 to 100 in a static method
3, before printing the value, we set a breakpoint, the debug tool shows the value does not change, still -1.
4, the printing result has a correct output which is 100.
VS2012 edition:11.0.60610.01 update3 by x64 debug
OS:Win7 x64 utilmate
你可以在下面这个链接查看你的问题:https://connect.microsoft.com/VisualStudio/feedback/details/797989/incorrect-display
Sunny Cao
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已编辑 Anna CcModerator 2013年8月21日 10:06 add link
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
-
静态存储,如果连接性是对外的,不能加static。 换句话说就是如果你在一个文件中声明了一个全局变量,如果想在另一个文件中使用,就不能加static。 所以你去掉static声明一下这个静态变量。
雷神
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
-
也许你再按一下F11就没有问题了,因为你的断点调试貌似还没进行到下一行断点设置处,你的IDE显示当前指向了printf这一行,但是这一行还没有运行,按F11调试指向下一行才能在监视中看到printf的运行情况。
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
全部回复
-
请在Watch/Autos窗口中观察,如下图所示:
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
-
你好:
根据你的描述,为了你的问题能过得到更好的解决,我把你的问题提到了connect上,在connect上会有对这个产品比较熟悉的人来参与你的问题。
下面是你问题的英文描述:
The steps to repro as below:
1, assign a static global variable g_Port as -1
2, change the value g_Port from -1 to 100 in a static method
3, before printing the value, we set a breakpoint, the debug tool shows the value does not change, still -1.
4, the printing result has a correct output which is 100.
VS2012 edition:11.0.60610.01 update3 by x64 debug
OS:Win7 x64 utilmate
你可以在下面这个链接查看你的问题:https://connect.microsoft.com/VisualStudio/feedback/details/797989/incorrect-display
Sunny Cao
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- 已编辑 Anna CcModerator 2013年8月21日 10:06 add link
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
-
静态存储,如果连接性是对外的,不能加static。 换句话说就是如果你在一个文件中声明了一个全局变量,如果想在另一个文件中使用,就不能加static。 所以你去掉static声明一下这个静态变量。
雷神
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42
-
也许你再按一下F11就没有问题了,因为你的断点调试貌似还没进行到下一行断点设置处,你的IDE显示当前指向了printf这一行,但是这一行还没有运行,按F11调试指向下一行才能在监视中看到printf的运行情况。
- 已标记为答案 VisualElevenModerator 2015年1月5日 2:42