Pointers, Schmointers

Pointers, Schmointers

Eric Smith
Eric Smith

October 01, 2011

I'm writing this blog from the train, my head hung in shame.

I'm taking a course in Game Optimization and today something exceptionally embarrassing happened. We had a pop quiz on pointer arithmetic and I, well I bombed it. I did C and C++ programming for almost 8 years, but when a fundamental concept came up I didn't have a clue. I have decided this test shall forever be known as the "embarrassing pointer test." Actually it deserves capitalization: "The Embarrassing Pointer Test!" I completely forgot my pointer arithmetic, mixed up the difference between Big Endian and Little Endian, and wasn't 100% sure that what %x would display in a printf statement. Yuck. Hopefully I won't be begging the professor for a job in the near future, although if I do I'll remind him I got A's in his other classes. "Hey Prof? Remember that Network Games class? That was hard right?"

Fortunately the purpose of class is not to impress the teacher but to learn, so I've decided to refresh my memory. The reason I failed the quiz wasn't because I've never done pointer arithmetic, in fact I have the memory manager I wrote for a different class right here. The reason is largely rust, and I can clean up this rust with a little practice. So I fired up Eclipse and wrote a simple C koan, which I am now publishing.

This koan does not use a unit testing framework, because instead of spending the entire ride setting up a framework and placing other yaks in my own way I got down to brass tacks and just wrote the code. The koans look like this:

unsigned char* p = new unsigned char[BUFFER_SIZE];
for (int i = 0; i < BUFFER_SIZE; i++)
				p[i] = i;
assert(p[0] == 0);
assert(*p == 0);

When you run the program the asserts are triggered, and you change the answers to the correct ones to continue. When you're done wipe away your changes, and start from the beginning next time. Do this a few times and you'll have your basic pointer arithmetic down, hopefully before your professors unleash a pop quiz.

Other koans can be found at:

Author's Note: This blog was originally written from a train without wi-fi. The tone reflects the mood I was in at the time and I have kept the text as close to the original as possible. Clearly the koan and this blog were actually published after I got off the train.