Microsoft KB Archive/98288

{|
 * width="100%"|

Watching Local Variables That Are Also Globally Declared

 * }

Q98288

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), versions 3.1, 3.5, 3.51, 4.0

-

SUMMARY
Consider debugging the following program in WinDbg:

  int x = 1; int y = 2; void main {     int x = 2; x++; y++; } Notice that there is a global variable x and a local variable x.

Before you step into main, if you set watchpoints on x and y, the Watch window will display a value for y but for x will say &quot;Expression cannot be evaluated.&quot; To see the value for x, use ::x and x will evaluate to the local x in main once you've stepped into main.

MORE INFORMATION
When debugging an application, the X86 C++ evaluator is loaded. Given this, you can use the scope resolution operator in a watch statement to view a hidden global variable. Without the use of the scope resolution operator, there is no way (short of watching it in a memory window) to watch a hidden global variable.

Additional query words: 3.10 3.50 4.00 95

Keywords :

Issue type :

Technology :