I’m going to risk being called a dunce for not picking up on this until now, because I think there are probably other people with this annoying problem too. When you’re debugging in VC++, by default raw pointers only display a single item when you expand them, like this:

Now, if you know this pointer is actually a series of items and not just one, you really want to inspect them all – you can add array indices (pFoo[n]) but this is awkward if you want to browse rather than cherry-pick single items. I’ve sometimes used the ‘memory’ view to get around this, which is especially useful if you’re looking at an array of bytes, but arrays of floating point values aren’t that readable via the memory view.
The way to force VC++ to display raw pointers as arrays is to add ‘,n’ to the end of the watch expression, like this:

And if you want to skip a bunch of items, just use pointer arithmetic as usual, such as (pFoo + 50),100 showing items 50-150.
If you knew this already and think I’m a muppet for only just figuring this out, bully for you (although why didn’t you tell me, you bastard?
). I’m hoping to help the poor saps like me who have found this clunky in the past.









July 8th, 2008 at 11:07 am
There is also a nice new feature on VS2008 – http://blogs.msdn.com/saraford/archive/2008/06/13/did-you-know-you-can-use-tracepoints-to-log-printf-or-console-writeline-info-without-editing-your-code-237.aspx
July 8th, 2008 at 11:15 am
gdb uses pFoo@num to access arrays, adding to the original array pointer is possible as well.
July 8th, 2008 at 1:17 pm
You’re a dunce, but so am I. I’ve always cursed and gone and opened a memory window until now.
July 8th, 2008 at 2:04 pm
You might already be aware of it but I will assume not based on what you say in the post.
.
You can define the type of the data you are looking at in a memory window, so it becomes far easier than looking at byte values
July 8th, 2008 at 2:30 pm
Why didn’t you tell me, you bastard?
The msdn blog link is also useful. Thanks John.
July 8th, 2008 at 2:56 pm
I didn’t know that, thanks for sharing!
What would be most useful for me is to be able to find out when a particular member variable changes value. If anybody knows of a way to track this that would be awesome. (for example, to have a breakpoint hit when foo changes from true to false)
July 8th, 2008 at 3:06 pm
@John: handy – although not quite worth upgrading for
@Fabien: ah, didn’t realise that, thanks; and there was I, transposing big-endian sequences in my head :/
@KungFooMasta: put a breakpoint somewhere that the member is in scope, then when it breaks, Debug > New Breakpoint > New Data Breakpoint, then enter the symbol (which must resolve to a memory address), and the number of bytes to watch for changes.
July 8th, 2008 at 3:11 pm
@KungFoo: Right-click the breakpoint and select Condition.
July 8th, 2008 at 3:16 pm
Ahh you are wise Glasshopper!
July 8th, 2008 at 3:31 pm
@Dan: that way it will only break at that specific line when a condition is met, that’s not quite the same as breaking whenever a given data member changes.
July 8th, 2008 at 4:20 pm
I came across this two years ago (while writing a course on advanced programming techniques), this was a great discovery, nobody in my lab new this trick, so it is good you share it on your blog.. many people will read this which didn’t know this trick and will be very thankful!
Btw. I found it here (some other tips and tricks are there as well, although less useful for me
): http://www.highprogrammer.com/alan/windev/visualstudio.html
July 8th, 2008 at 5:17 pm
Very nice list of tips&tricks along with a nice ‘watch’ codes list debugger variable :
http://www.catch22.net/tuts/vctips.asp
While we’re on C++ debugging tricks, replacing WIN32 horrible ‘assert()’ with one that actually break at the good place (meaning NOT inside win32 internals), still not cost anything in release, and with more capabilities :
http://powerof2games.com/node/10
July 8th, 2008 at 10:32 pm
Arrays? I almost never use arrays. Tell me I’m missing something.
July 8th, 2008 at 10:39 pm
You’re missing something.
We’re talking about pointers here. Any time you deal with a memory block full of floats, ints, whatever (something you’ll do a lot if you process things like vertex / index buffers), it’s useful to be able to browse the content just from a single pointer, AS IF it were an array.
July 9th, 2008 at 9:15 am
Those Tracepoints are available in VS 2005 too! Just right click on a breakpoint icon and tweek the When Hit…
July 9th, 2008 at 12:09 pm
So they are! Very useful, thanks.
July 9th, 2008 at 5:22 pm
Oh sorry Steve, I hadn’t fully understood. I got it now.