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! πŸ™‚

3 thoughts on “Variable value is always’s zero, no matter what you do!

  1. 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.

Appreciate your comments...