Visual Studio 2012 c ++中的指令指针问题 [英] Problems with instruction pointer in Visual Studio 2012 c++

查看:136
本文介绍了Visual Studio 2012 c ++中的指令指针问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2012,c ++和/ clr。



当我正在调试函数void foo2(int w,int h)时,移动指令指针以任何方式,我的参数w和h被重置为零!



代码:

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:

// 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
    ...
}





当我以任何方式在void foo2(int w,int h)中移动指令指针时,参数w和h的值重置为零!



我尝试禁用任何优化并尝试更改项目选项,但没有任何帮助。当然,我不是处于发布模式。



另外,另一个问题,(不太重要)是当声明中的参数名称和函数的实现中没有同样,调试器看不到值。



例如:



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:

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





任何帮助?



Any help?

推荐答案

你的问题是变量的范围,因为你的名字不好(而且太短)。你有w和h不仅仅作为班级成员,而且还作为功能参数。



有一个匈牙利表示法,每个班级成员得到一个m_ 和类型(i表示int)前缀:



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:

int m_iw;
int m_ih;





下一步和真正的McCoy也给出了说话的名字:





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

int m_iWidth;
int m_iHeight;


这篇关于Visual Studio 2012 c ++中的指令指针问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆