One of the joys of working with C++ is the ability to get ‘down to the metal’ and talk to the hardware directly. Not only can this direct-access improve performance, as a pedagogical tool it allows us to peek under the hood at raw assembly high-level code produces. This can have the effect of demystifying many aspects of programming, as while high-level languages make coding more efficient, they hide much of how things actually work.
One such example of this is with pointers. In C++ we learn that pointers are objects that hold a reference to some other objects memory location. We’re taught to dereference and pass pointers to functions, how to avoid stray and dangling pointers, and if we’re former Java developers, what all those Null Pointer errors actually meant.
Of course despite this deeper understanding even C++ hides what pointers truly are and how they’re represented and manipulated in hardware.
In this post then I want to quickly look at pointers from the standpoint of assembly language so next time you use one, you’ll have a better idea of what one actually is at the most basic level. This may even make learning what pointers are easier for newcomers.
I also, of course, want to talk performance.