CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Wild pointer??

  1. #1
    Join Date
    Jul 2003
    Posts
    79

    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?

  2. #2
    Join Date
    May 2000
    Location
    Washington DC, USA
    Posts
    715
    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.

  3. #3
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    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.

  4. #4
    Join Date
    Jul 2003
    Posts
    79
    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
  •  





Click Here to Expand Forum to Full Width

Featured