title: Incorrect watch values in Visual Studio 2010 Professional
body: <p>I'm having a really bizarre problem wherein the watch window values for some variables don't seem to match their "real world" values. The debugger just appears to be off in space. Here's the tiniest code snippet that shows it:</p>
  
  <pre><code>printf("%d", pNodes[nNode].nColumn); // watch shows "4"
  printf("%d", nColumn); // watch shows "1"
  
  if (pNodes[nNode].nColumn != nColumn)
    continue; // this is NOT called
  </code></pre>
  
  <p>So here's the behaviour:</p>
  
  <ol>
  <li>If I add a watch to <code>pNodes[nNode].nColumn</code>, it shows a value of <code>4</code>.</li>
  <li>If I add a watch to <code>nColumn</code>, it shows a value of <code>1</code>.</li>
  <li>If I check the expression  <code>pNodes[nNode].nColumn != nColumn</code> in the watch window, it evaluates to <code>true</code>.</li>
  <li>The <code>continue</code> statement is skipped!</li>
  <li>I added the <code>printf()</code> calls to see what was going on, and the <code>printf()</code> prints the values <code>1</code> and <code>1</code>, which seems to agree with the way the code "flows" (i.e. that it does <em>not</em> call the <code>continue</code> inside the <code>if</code> statement.</li>
  </ol>
  
  <p>I can even check the memory at <code>&amp;pNodes(nNode].nColumn</code>, and the memory shows the "incorrect" values that the watch window is showing me. So it seems like the debugger is getting completely "disconnected" from the actual program data or something. I'm running a debug build optimizations are turned off. I've also checked that pNodes does not correspond to some global variable or other variable higher in scope -- it seems there's only a local version.</p>
  
  <p>This is completely baffling to me! I'm not even sure where to go next to try to figure out the problem. If you have any ideas whatsoever, I'd love to hear them!</p>
  
  <p>Thanks!</p>