Home > Strange bugs > Variable value is always’s zero, no matter what you do!

Variable value is always’s zero, no matter what you do!

Recently a friend of mine (sitting just behind me) had a strange problem. I wrote an inline function which was like…

void SetBlah( const bool IsBlah ) { m_IsBlah = IsBlah; }

Now he was using this function since we work for the same project! So he had a value 1 for IsBlah when calling this function but no matter what he did m_IsBlah always had the value zero!

He spent half a day trying to solve this issue, I too joined him in this venture. We thought it has got something to do with inlining the function call so we made it non inlined but this didn’t solve the issue. No matter what we did still the value was zero, we tried rebuilding the project but no effect whatsoever.

I tried running the code on my machine and it was fine, working as it should be!

So in the end I found out the problem? But before I post the answer here, any idea what could be the reason?

Answer

He had a statement in his watch window like…

theStaticLongNameObject.m_IsBlah = 0;

This expression prevented the value from changing. Also we can’t see the full expression in watch window because of the variable’s long name! 🙂

Advertisements
  1. May 28, 2008 at 9:53 am

    Indeed, nice guess? 🙂

  2. Tobias Langner
    May 21, 2008 at 10:56 am

    I guess the watch statement assigned ( = ) 0 after each step in the debugger. What was meant, was thisStaticLongNameObject.m_IsBlah == 0 – the test for zero.

  3. May 8, 2008 at 4:22 pm

    And I am that unlucky friend who spend a half day on that nasty bug. 😀

    Regards,
    Jijo.
    http://weseetips.com

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: