Click here to Skip to main content
15,883,825 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am using Visual Studio 2012, c++ with /clr.

When i'm debugging function void foo2(int w, int h), and move instruction pointer in any way, my arguments w and h are reset to zeros!

Code:
C++
// MyClass.h
public ref class MyClass
{
public:
    foo1(int a, int b);
    foo2(int w, int h);
};

// FrmMain.cpp
System::Void MyApp::FrmMain_Load(System::Object^ sender, System::EventArgs^ e)
{
    MyClass myObj;
    myObj.foo1(1, 2);
}

// MyClass.cpp
void MyClass::foo1(int a, int b)
{
    ...
    int w = 100;
    int h = 200;
    foo2(w, h);
    ...
}

void MyClass::foo2(int w, int h)
{
    int x = 5;  // some line n1
    int y = 10; // some line n2
    ...
}


When i move instruction pointer in void foo2(int w, int h) in any way, values for arguments w and h reset to zero!

I tried disabling any optimizations and tried changing project options but nothing helps. Of course, i'm not in release mode.

Also, another problem, (less important) is that when arguments names in declaration and in implementation of function are not same, debugger cannot see values.

example:
C++
void foo(int w1, int h1);
void foo(int w, int h)
{
  // debugger dont see w and h at all
}


Any help?
Posted
Comments
Albert Holguin 28-Dec-13 15:57pm    
What do you mean by "when I move my instruction pointer"? Specify where you break, and how you "move your instruction pointer".
Philippe Mori 16-Jan-14 22:51pm    
Does the variable is used afterward? If not, then the compiler might reuse that memory for another purpose (probably even if optimization are turned off).

In such case, just ignore the values displayed by the debugger.

1 solution

your problem is the "scope" of the variables, because you have bad (and too short) names. You have the w and h NOT ONLY as class members, but also as function parameters.

There is a "hungarian notation", where every class member gets a "m_" and type ("i" for int) prefix:

C++
int m_iw;
int m_ih;


the next step and "the real McCoy" too give speaking names:

C++
int m_iWidth;
int m_iHeight;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900