Archive

Posts Tagged ‘Watch window’

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

May 8, 2008 3 comments

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! 🙂

Seeing array values in the debugger as a list!

VC debuggger has a nice feature to display array values. It works with any contiguous data, for e.g. vector, CArray, native type arrays etc.

Follow these steps…

  1. IntVector is an array of integers
  2. Start quick watch by pressing Shift + F9 with IntVector object selected
  3. Select _First(encircled in red) and press Add watch(encircled in red)
  4. You should see _First in the watch window
  5. So now put a comma after _First and add number of elements to view

Here is a screen shot of how I get to see a vector’s array values in the debugger.

Watch demo

See above result in watch window, easy isn’t it? Works in the same way for other array types too!

So have a great time debugging arrays 😉

%d bloggers like this: