Fog Creek Software
Discussion Board

One way to teach C++

Hi everyone,

I was just looking though the code for a virtual function call and I think I found a good way to describe it...

lea        ecx,[esp+0Ch]
; load the pointer to the object

mov      edx,dword ptr [ecx]
; load the pointer pointed to by the pointer to the object

call        dword ptr [edx]
; call the function pointer pointed to by the pointer pointed to by the pointer to the object

Monday, June 28, 2004

Or, you could draw and label dots (pointers) and connect them (the reference) on the blackboard.  I'm a fine arts major, i like pictures.

Monday, June 28, 2004

Yes, definitely worth a picture.  I know what's going on, so your 'Pointer to the function pointed to...' statement didn't lose me -- it's quite clever really.

However, even though it's real it SOUNDS like a joke.  A picture to go along with it would show how it is really true.

Monday, June 28, 2004

Allan, of course it's a joke. A couple of indirections, big deal.

I just couldn't resist "reading it" that way... ;)

Monday, June 28, 2004

Is that x86 assembly?  Hasn't that been classified "obscene" by now?

Monday, June 28, 2004

It's ok for consenting adults in private ;-)

Martin Beckett
Tuesday, June 29, 2004

Here's an interesting document about using COM in x86.

The strange thing is that I find COM easier to understand in ASM.  I only have to wory about bytes and not several layers of syntax.

Ged Byrne
Tuesday, June 29, 2004

Indeed, Ged :) Perhaps the best way to cure fear of pointers is to through ASM first, otherwise one will never have a mental model of what's happening.

Wednesday, June 30, 2004

*  Recent Topics

*  Fog Creek Home