Understanding and Using C Pointers

:: software

A C programmer preparing to use pointers

A C programmer preparing to use pointers

Someone1 in my Google+ circles posted about Understanding and Using C Pointers, a fairly recent (May, 2013) book by Richard Reese.

Here’s the actual summary from oreilly.com:

Understanding and Using C Pointers

Improve your programming through a solid understanding of C pointers and memory management. With this practical book, you’ll learn how pointers provide the mechanism to dynamically manipulate memory, enhance support for data structures, and enable access to hardware. Author Richard Reese shows you how to use pointers with arrays, strings, structures, and functions, using memory models throughout the book.

Difficult to master, pointers provide C with much flexibility and power—yet few resources are dedicated to this data type. This comprehensive book has the information you need, whether you’re a beginner or an experienced C or C++ programmer or developer.

On the one hand, it makes me feel old to realize how many programmers have grown up not needing to learn this. On the other hand, it’s neat that people still want to learn it and appreciate the value of knowing it.

Even when using a higher-level language, there will be times when it’s helpful to have a sense of what’s actually going on at the lower levels. Programming bigger systems involves various levels of abstraction. Usually the trick is pretending that you don’t know how the lower levels work—avoiding the temptation to use details about lower levels and break the barrier of abstraction. However when things aren’t performant, it helps to use your X-ray vision and look through the barriers.

My first (and only) two CS classes were about Pascal and assembly. Those turned out to be perfect preparation for teaching myself C, which in some ways is a synthesis of both.

One issue with C pointers is that people need to learn both new concepts and new notation. Anyone who doesn’t get a headache the first time they see the notation for a function pointer is a weird space alien. Combine that notation with learning the idea of “a pointer to a function”, and it’s going to be difficult.

I can vaguely recall that experience learning C. Much more recently I remember examples with, say, continuations and macros in Scheme and Racket.

Maybe it would help to provide some training wheels that use “plain English” instead of “weird” or “concise” notation. Or maybe not. Maybe it’s just hard and you need to slog through it.

Anyway, here are my imaginary review quotes for any book about C pointers:

Again, these are pretend reviews. The real reviews are very positive and it looks like an excellent book that you should buy4 immediately.

  1. Although I want to give them credit, they shared the post privately so I don’t want to presume to name them. 

  2. For movable allocated memory, older versions of Windows used opaque HANDLEs you could cash in for real pointers. 

  3. Whereas Mac OS used pointers to pointers, if I recall correctly. 

  4. Not an affiliate link.