|
-
February 9th, 2004, 01:57 PM
#1
Wild pointer??
Yesterday I had a very strange behaviour when debugging my code.
I used an index variable,
int n=0;
When debugging this index variable was incremented by two severeal times though it should'nt have been when looking at the code.
I added to the code,
n=0;
n=1;
n=5;
n=7;
What was shown in the watch window when stepping these lines was,
n=2
n=4
n=6
n=8
The code is inside a worker thread. I solved the problem by re using an other index variable instead. But I think I better know what is causing this behaviour.
Anybody with an idea?
-
February 9th, 2004, 02:29 PM
#2
I think you're right.. You should figure it out.
Is it a global variable or a local variable? If it's a global is the other thread touching it?
if it's a member variable is it possible your watch window was looking at the wrong instance of the variable.
As a general rule you can only see this type of behavior if you are actually changing the value explicitely in your code somewhere. The exception to the rule is if you're walking on memory, overwriting another variable defined next to this one and thus overwriting this ones value. Since your "unexplainable" values are so clean I think the former explination is probable the one I would check on first.
what pointer are we talking about though? this is a variable here... where do you get the title "wild pointer" from?
Good luck.
-
February 9th, 2004, 02:34 PM
#3
Originally posted by JMS
if it's a member variable is it possible your watch window was looking at the wrong instance of the variable.
Good luck.
or incrementing it in the watch window on accident
To the Original Poster: too many things can cause this behaviour watch the address of the index var in the memory window for when it changes, walk through your code via the disassembly view.
-
February 9th, 2004, 03:06 PM
#4
n is not a global variable.
I did'nt think of the possibility that I was looking at the wrong "n" in the watch. I still think it's strange that another n is incrementing while stepping through code. Is the main thread "moving" while I step through a worker thread?
What I meant with wild pointer was that my main concern was that a pointer was writing in addres of n.
I don't know if this is possible with a local variable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|