Variable value is always's zero, no matter what you do! [modified]
-
Don't know if this is a subtle bug, but anyway... 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!
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
modified on Thursday, May 8, 2008 5:25 AM
-
Don't know if this is a subtle bug, but anyway... 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!
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
modified on Thursday, May 8, 2008 5:25 AM
How is
m_IsBlah
declared?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
How is
m_IsBlah
declared?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
How is m_IsBlah declared?
private: bool m_IsBlah; Well as a hint, it will work fine if it's not being debugged! ;)
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
-
CPallini wrote:
How is m_IsBlah declared?
private: bool m_IsBlah; Well as a hint, it will work fine if it's not being debugged! ;)
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
But it is also system dependent, I suppose: my debugger shows it working fine. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
But it is also system dependent, I suppose: my debugger shows it working fine. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
But it is also system dependent, I suppose: my debugger shows it working fine. [Smile]
No, :) It's not system dependent, but it's just a stupid mistake done in one of the debugger windows(can't give a better hint than this one).
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
-
CPallini wrote:
But it is also system dependent, I suppose: my debugger shows it working fine. [Smile]
No, :) It's not system dependent, but it's just a stupid mistake done in one of the debugger windows(can't give a better hint than this one).
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
m_IsBlah = false
in watch window?Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
-
m_IsBlah = false
in watch window?Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
Mladen Jankovic wrote:
m_IsBlah = false in watch window?
Yes, good guess! :)
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
-
Mladen Jankovic wrote:
m_IsBlah = false in watch window?
Yes, good guess! :)
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
I had a quite similar Visual Studio behaviour right now. While debugging an executable (
DEBUG
build) I stepped inside the code of aDLL
(RELEASE
build) and there appeared such inconsistecies. My (empirical) solution was building theDEBUG
version of theDLL
. I don't know if the above puts some light into your problem. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Don't know if this is a subtle bug, but anyway... 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!
Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http://nibuthomas.wordpress.com
modified on Thursday, May 8, 2008 5:25 AM