神秘变化的变量 [英] Mysteriously changing variable

查看:58
本文介绍了神秘变化的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只用C ++做了一点编程,所以我还在学习,但是我有一个变量在我身上变化的问题。我尝试了这个

2种方法,结果相同。我有一个私有长变量,无条件地改变

。我有一个跟踪文件运行告诉我什么是

正在进行中。这是一种正在发生的事情


l_myVariable

将l_myVariable发送到tracefile

调用方法

将l_myVariable发送到跟踪文件


该方法只是一个while循环,等待某些条件发生之前发生
。跟踪文件第一次显示25,然后

在第二次尝试写入时崩溃。我以为它是一个

私有变量,其他一些方法可能会以某种方式改变它,所以我把它改成了一个局部变量并再次尝试了这个

long l_localVariable = l_myVariable

将l_localVariable发送到tracefile

调用方法

将l_localVariable发送到tracefile


在这种情况下,它不会崩溃,但跟踪文件第一次显示25次

和第二次131076。为什么我的变量会改变???

解决方案

奥特曼写道:

我只做了一点点用C ++编程所以我还在学习,但是我对变量的问题有所改变。我尝试了两种方法,结果相同。我有一个私有的长变量,无缘无故地改变。我有一个跟踪文件正在运行,告诉我
正在进行中。这是发生了什么事情

l_myVariable
发送l_myVariable到tracefile
调用方法
发送l_myVariable到tracefile

方法只是一个while循环,等待某些条件发生之前发生。跟踪文件第一次显示25,然后在第二次尝试写入时崩溃。我认为这是一个私有变量,其他一些方法可能会以某种方式改变它,所以我把它改成了一个局部变量并再次尝试了这个

long l_localVariable = l_myVariable
将l_localVariable发送到tracefile
调用方法
将l_localVariable发送到tracefile

在这种情况下,它不会崩溃,但跟踪文件第一次显示25第二次和第131076次。为什么我的变量会改变?




您可能有缓冲区溢出。如果

包含l_myVariable成员变量的对象本身就是局部变量,则尤其如此。如果

就是这种情况,那么有人会在你的筹码上乱涂乱画。在VC.NET中,

/ GS选项可能会检测到这一点:


/ GS(缓冲区安全检查)
http://msdn.microsoft .com / library / de ... erSecurity.asp


如果您无法通过跟踪发现它,可以尝试设置数据/ >
breakpoint" ;;搜索帮助以获取详细信息。


-

Doug Harrison

Microsoft MVP - Visual C ++


我使用的是C ++ 6,这是一个com dll,因此断点不起作用。这个

是我必须使用跟踪文件的原因。我在我的

方法中对该变量进行了跟踪,整个过程为25,但只要它存在方法,

变量就会发生变化。我将局部变量更改为静态长并且它保持值为b $ b值,但我不认为我想要它是静态变量。


Doug Harrison [MVP]" < ds*@mvps.org>在消息中写道

news:m0 ******************************** @ 4ax.com ...

Altman写道:

我只用C ++做了一点编程,所以我还在学习但是我是 >对我变化的变量有问题。我已经尝试了这两种方式同样的结果。我有一个私有的长变量,无缘无故地改变。我有一个跟踪文件正在运行,告诉我
正在进行中。这是发生了什么事情

l_myVariable
发送l_myVariable到tracefile
调用方法
发送l_myVariable到tracefile

方法只是一个while循环,它等待某些条件发生之前就会发生。跟踪文件第一次显示25,然后
在第二次尝试写入时崩溃。我以为它是一个私有变量,其他一些方法可能会以某种方式改变它,所以我将
更改为局部变量并再试一次这样的

long l_localVariable = l_myVariable
将l_localVariable发送到tracefile
调用方法
将l_localVariable发送到tracefile

在这种情况下它不会崩溃但是跟踪文件显示25第一次
和131076第二次。为什么我的变量会改变???



你可能有一个缓冲区溢出。如果包含l_myVariable成员变量的对象本身是局部变量,则尤其可能。如果是这样的话,那么有人会在你的筹码上乱涂乱画。在VC.NET中,
/ GS选项可能会检测到这一点:

/ GS(缓冲区安全检查)
http://msdn.microsoft.com/library /de...erSecurity.asp

如果你无法通过追踪发现它,你可以尝试设置一个数据
断点;搜索帮助以获取详细信息。

-
Doug Harrison
Microsoft MVP - Visual C ++



断点应该适用于COM DLL,没有什么特别的COM

DLL。你能告诉我们你的尝试以及为什么你认为断点没有工作吗?


Ronald Laeremans

Visual C ++团队


" Altman" <否****** @ SickOfSpam.com>在消息中写道

news:uP ************** @ TK2MSFTNGP12.phx.gbl ...

我正在使用C ++ 6这是一个com dll所以断点不起作用。这就是我必须使用跟踪文件的原因。我在我的
方法中对该变量进行了跟踪,并且它在整个过程中都是25,但是只要它存在方法,
变量就会改变。我将局部变量更改为静态长并且它保持了它的值,但我不认为我希望它是静态变量。

Doug Harrison [MVP] " < ds*@mvps.org>在消息中写道
新闻:m0 ******************************** @ 4ax.com ... < blockquote class =post_quotes> Altman写道:

我只用C ++做了一点编程,所以我还在学习但是我有一个问题一个变化在我身上的变量。我已经尝试了这两种方式同样的结果。我有一个私有的长变量,无缘无故地改变。我有一个跟踪文件正在运行,告诉我
正在进行中。这是发生了什么事情

l_myVariable
发送l_myVariable到tracefile
调用方法
发送l_myVariable到tracefile

方法只是一个while循环,它等待某些条件发生之前就会发生。跟踪文件第一次显示25,然后
在第二次尝试写入时崩溃。我以为它是一个私有变量,其他一些方法可能会以某种方式改变它,所以我将
更改为局部变量并再试一次这样的

long l_localVariable = l_myVariable
将l_localVariable发送到tracefile
调用方法
将l_localVariable发送到tracefile

在这种情况下它不会崩溃但是跟踪文件显示25第一次
和131076第二次。为什么我的变量会改变???



你可能有一个缓冲区溢出。如果
包含l_myVariable成员变量的对象本身就是一个局部变量,这种情况尤其可能。
如果是这样的话,那么有人会在你的堆栈上乱涂乱画。在VC.NET中,
/ GS选项可能会检测到这一点:

/ GS(缓冲区安全检查)
http://msdn.microsoft.com/library /de...erSecurity.asp

如果你无法通过追踪发现它,你可以尝试设置一个数据
断点;搜索帮助以获取详细信息。

-
Doug Harrison
Microsoft MVP - Visual C ++




I have only done a little programming in C++ so I am still learning but I am
having a problem with a variable that is changing on me. I have tried this
2 ways with the same result. I have a private long variable that keeps
changing for no reason. I have a trace file running to tell me what is
going on. Here is kind of what is happening

l_myVariable
send l_myVariable out to tracefile
Call a method
send l_myVariable out to tracefile

The method is simply just a while loop that waits for certain conditions to
occur before it breaks out. The trace file shows 25 the first time and then
crashes when trying to write the second time. I thought being it was a
private variable some other method might somehow be changing it so I changed
this to a local variable and tried it again like this
long l_localVariable = l_myVariable
Send l_localVariable out to tracefile
call the method
Send l_localVariable out to tracefile

In this case it does not crash but the trace file shows 25 the first time
and 131076 the second time. Why is my variable changing???

解决方案

Altman wrote:

I have only done a little programming in C++ so I am still learning but I am
having a problem with a variable that is changing on me. I have tried this
2 ways with the same result. I have a private long variable that keeps
changing for no reason. I have a trace file running to tell me what is
going on. Here is kind of what is happening

l_myVariable
send l_myVariable out to tracefile
Call a method
send l_myVariable out to tracefile

The method is simply just a while loop that waits for certain conditions to
occur before it breaks out. The trace file shows 25 the first time and then
crashes when trying to write the second time. I thought being it was a
private variable some other method might somehow be changing it so I changed
this to a local variable and tried it again like this
long l_localVariable = l_myVariable
Send l_localVariable out to tracefile
call the method
Send l_localVariable out to tracefile

In this case it does not crash but the trace file shows 25 the first time
and 131076 the second time. Why is my variable changing???



You may have a buffer overrun. This is especially likely if the object that
contained the l_myVariable member variable was itself a local variable. If
that was the case, then someone is scribbling on your stack. In VC.NET, the
/GS option might detect this:

/GS (Buffer Security Check)
http://msdn.microsoft.com/library/de...erSecurity.asp

If you can''t discover it by tracing, you could try setting a "data
breakpoint"; search the help for details.

--
Doug Harrison
Microsoft MVP - Visual C++


I am using C++ 6 and this is a com dll so breakpoints will not work. This
is why I have to use a trace file. I put a trace on that variable in my
method and it is 25 the whole way, but as soon as it exists the method, the
variable changes. I changed the local variable to a static long and it kept
it''s value but I don''t think I want it a static variable.

"Doug Harrison [MVP]" <ds*@mvps.org> wrote in message
news:m0********************************@4ax.com...

Altman wrote:

I have only done a little programming in C++ so I am still learning but I
am
having a problem with a variable that is changing on me. I have tried
this
2 ways with the same result. I have a private long variable that keeps
changing for no reason. I have a trace file running to tell me what is
going on. Here is kind of what is happening

l_myVariable
send l_myVariable out to tracefile
Call a method
send l_myVariable out to tracefile

The method is simply just a while loop that waits for certain conditions
to
occur before it breaks out. The trace file shows 25 the first time and
then
crashes when trying to write the second time. I thought being it was a
private variable some other method might somehow be changing it so I
changed
this to a local variable and tried it again like this
long l_localVariable = l_myVariable
Send l_localVariable out to tracefile
call the method
Send l_localVariable out to tracefile

In this case it does not crash but the trace file shows 25 the first time
and 131076 the second time. Why is my variable changing???



You may have a buffer overrun. This is especially likely if the object
that
contained the l_myVariable member variable was itself a local variable. If
that was the case, then someone is scribbling on your stack. In VC.NET,
the
/GS option might detect this:

/GS (Buffer Security Check)
http://msdn.microsoft.com/library/de...erSecurity.asp

If you can''t discover it by tracing, you could try setting a "data
breakpoint"; search the help for details.

--
Doug Harrison
Microsoft MVP - Visual C++



Breakpoints should work on a COM DLL, there is nothing special about a COM
DLL. Can you tell us what you tried and why you think breakpoints don''t
work?

Ronald Laeremans
Visual C++ team

"Altman" <No******@SickOfSpam.com> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...

I am using C++ 6 and this is a com dll so breakpoints will not work. This
is why I have to use a trace file. I put a trace on that variable in my
method and it is 25 the whole way, but as soon as it exists the method, the
variable changes. I changed the local variable to a static long and it
kept it''s value but I don''t think I want it a static variable.

"Doug Harrison [MVP]" <ds*@mvps.org> wrote in message
news:m0********************************@4ax.com...

Altman wrote:

I have only done a little programming in C++ so I am still learning but I
am
having a problem with a variable that is changing on me. I have tried
this
2 ways with the same result. I have a private long variable that keeps
changing for no reason. I have a trace file running to tell me what is
going on. Here is kind of what is happening

l_myVariable
send l_myVariable out to tracefile
Call a method
send l_myVariable out to tracefile

The method is simply just a while loop that waits for certain conditions
to
occur before it breaks out. The trace file shows 25 the first time and
then
crashes when trying to write the second time. I thought being it was a
private variable some other method might somehow be changing it so I
changed
this to a local variable and tried it again like this
long l_localVariable = l_myVariable
Send l_localVariable out to tracefile
call the method
Send l_localVariable out to tracefile

In this case it does not crash but the trace file shows 25 the first time
and 131076 the second time. Why is my variable changing???



You may have a buffer overrun. This is especially likely if the object
that
contained the l_myVariable member variable was itself a local variable.
If
that was the case, then someone is scribbling on your stack. In VC.NET,
the
/GS option might detect this:

/GS (Buffer Security Check)
http://msdn.microsoft.com/library/de...erSecurity.asp

If you can''t discover it by tracing, you could try setting a "data
breakpoint"; search the help for details.

--
Doug Harrison
Microsoft MVP - Visual C++




这篇关于神秘变化的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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