Display wrong value in the watch window

  • Thread starter Thread starter Austin
  • Start date Start date
A

Austin

I converted a project from VC6 to VC7. There is a problem in one class
of this dll.
///Class1.h
class CClass1: base class
{
private:
int m_nTest;
public :
void Function1()
}
I access m_nTest in Function1 . Set the value of m_nTest to 8. But I
can not get the correct update in the watch window, still display 0.
But if I set the m_nTest to a temp declared variable, like int n =
m_nTest; then n equals 8(in the watch window). I try to look into the
Disassembly code. I found the address of m_nTest is not the same value
as sum of the class address and the offset(less 8 byte). That means I
can set and get the correct value of this class, but I can not see it
in the watch window. I think the project still has problem and it will
cause other issues sooner or later. So I want anyone give me some
suggestion about it.

Appriciate any of your comments.
 
I access m_nTest in Function1 . Set the value of m_nTest to 8. But I
can not get the correct update in the watch window, still display 0.

Are you trying to debug an optimised build of your project?

These apparent anomalies are common when you're doing that. Only if
you compile with /Od will the debugger give you a true representation
of the state of variables.

Dave
 
Dave, Thanks for your reply.

In my debug version, the value of Optimization is disabled (/Od). But
the watch window still displays the uncorrect value.
Do u mean it's ok to use the current code and project settings?
 
In my debug version, the value of Optimization is disabled (/Od). But
the watch window still displays the uncorrect value.

In that case, I don't understand why it should.

Can you reproduce this quirk in a simple test project?
Do u mean it's ok to use the current code and project settings?

If the end results you get are correct, you're seeing a quirk of the
debugger, not a real problem.

Dave
 
Back
Top