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:
printf("%d", pNodes[nNode].nColumn); // watch shows "4"
printf("%d", nColumn); // watch shows "1"
if (pNodes[nNode].nColumn != nColumn)
continue; // this is NOT called
So here’s the behaviour:
- If I add a watch to
pNodes[nNode].nColumn, it shows a value of4. - If I add a watch to
nColumn, it shows a value of1. - If I check the expression
pNodes[nNode].nColumn != nColumnin the watch window, it evaluates totrue. - The
continuestatement is skipped! - I added the
printf()calls to see what was going on, and theprintf()prints the values1and1, which seems to agree with the way the code “flows” (i.e. that it does not call thecontinueinside theifstatement.
I can even check the memory at &pNodes(nNode].nColumn, 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.
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!
Thanks!
So I think I’ve cracked the case: The culprit was Struct Member Alignment. I had a bunch of projects mixed together and some of them had varying values for this field inside the projects. I removed the settings on all of them to just let VS pick the defaults and the problem has disappeared.
The applicable value was between 4 bytes in some of the projects, Default in some of the projects, and empty altogether in others. The value is under Configuration Properties/ C/C++ / Code Generation / Struct Member Alignment. Again, I ended up just deleting the values altogether for the projects. I think this was set on the projects at some point in the past to deal with some kind of cross-platform issue, but at least it’s fixed for the work I’m doing now!
Thanks for all of your help!