Debugger Tips, Tricks and Tools #2

Use format specifiers or type-casting in Enhanced Datatips. 

Ever wish you could use our new enhanced datatips to see an expression that requires a format specifier or a cast?  For example, say you have var definition such as the following in your code:

   int *pa = new int[100];

Unfortunately, while debugging, if you hover over "pa" all you'll see in your datatip is (imagine the image, since I'm too lazy to add it right now):

   + pa | 0x12345678

Then if you hover over the +, you'll only see the first integer.  Not very useful if you want to see #51 in the array.  Yeah you could add it to the watch window, or you could do a QuickWatch on it.  But that's so 90's.  Instead, do the following:

  1. Open the Immediate or Command window if either isn't already opened.
  2. Type "pa,100" but don't bother entering it. (See this MSDN page for more information about C++ format specifiers.  C# also has format specifiers, but with the exception of "Ac", they aren't really of much use here.)
  3. Select the entire string you just added then hover the mouse over it. 

Voila! now you can use the enhanced datatips to view your variable with the format specifier. 

But wait! There's more!  What if you don't want to open the command or immediate window and type something just to do this?  Well, why not put the expression you'd like to see right inside the source file as a comment?  Something like this?

   // dbgexpr: pa,100
   int *pa = new int[10];

Or, you could even create you're own poor-man's watch window by adding a new text file to your project called "watches.txt".  The possibilities are limitless!  Well... that's maybe overstating it just a tad, but you get the idea!

Comments (0)

Skip to main content