• Advertisement
Sign in to follow this  

Static Variables in Debugging

This topic is 4762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was just running through my code line by line to make sure everything is working as it should. I noticed one of my variables, a static one, was behaving odd. I kept incrementing it ("++"), but it stayed the same in the debug window. However, in-game items behaved as they should, as if the variable was incrementing fine. I set up a dummy function: if( my_static_var == 6 ) { my_static_var = my_static_var } I pointed my cursor at the dummy statement in my function, and hit "Run to Cursor". That means if my static variable ever reaches 6 (which it doesn't in the debug window), the dummy statement would be executed, which means that "running to cursor" would be successful. Oddly enough, it was successful. So, even though the debug window would disagree, my variable does indeed reach 6. Anyone know what's wrong with this picture? It would be worth mentioning there is another place in my code that also increments that static variable, and that place works fine - the debug window shows what it should. EDIT: Problem in pictorial form. Observe the variable CurrentTile:

Share this post


Link to post
Share on other sites
Advertisement
x.cpp
    static int CurrentTile = 1;
struct foo
{
static int CurrentTile;
};
y.cpp
    static int CurrentTile = 2;
int bar()
{
static int CurrentTile;
}


There are four different variables here, all named "CurrentTile".

Share this post


Link to post
Share on other sites
[caution]

That's exactly what the problem was. I had another variable (that I was actually unaware of - it's been there so long, I don't remember putting it there) that was actually being displayed in the debug window.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement