Table of Contents
- Part 1: K&R
- Part 2: Zed Shaw’s Learn C the Hard Way
- Part 3: C Programming Substance Guidelines
- Part 4: What Should I Read? Why Should I believe you? (You are here.)
Why should I believe you?
When it comes to C, I am quite proficient. I’ve been employed professionally to write C. I created a somewhat popular open source project in C. I have extensive experience profiling C programs12, optimizing them34, and making them multithreaded5. I’ve contributed to other open source C projects. In short, if I’m not worth taking seriously on this topic, then very few people are.
How I Learned C
C was my first real programming language.6 I was introduced to it at the age of 13. Thanks to some luck and an advanced placement test, I was allowed to take up to two classes per semester at Gonzaga University. Wanting to learn more about programming, I enrolled in CS121.
I stuck out a little on campus.
I distinctly remember an early assignment where I was completely stumped by a bug. I’d almost finished the program, but there was one issue that I couldn’t fix. An
if statement was always evaluating to
TRUE, even when it shouldn’t. The
else was never taken. The program compiled without warnings. It was incredibly frustrating.
I spent two days staring at that code. I didn’t know about debuggers, so I peppered my code with
printf()s. I commented and uncommented chunks of code. No matter what I tried, I simply couldn’t understand why the program was misbehaving. I was almost in tears when I asked my dad for help. He saw the problem in seconds:
I had a single equals in a conditional. That meant I was assigning
b instead of comparing them. As soon as I added another equals, my program worked flawlessly. All that effort and frustration was caused by a single missing character.7
I think there has to be something seriously wrong with you in order to do this work. A normal person, once they’ve looked into the abyss, will say, “I’m done. This is stupid. I’m going to do something else.” But not us, ‘cause there’s something really wrong with us.
This was undoubtedly the most difficult educational experience of my life. I really did learn C the hard way.
So what should I read?
Honestly? I’m not sure. For those who want to to learn C, I have yet to find a book that I can unconditionally recommend. The only text I can personally suggest is the Kernighan and Ritchie book from part 1. As I said in that post, caveats apply.
For those who know some C and are looking to improve their skills, there are better resources. I’ve heard good things about Robert Love’s Linux Kernel Development (PDF). And though it covers much more than C, Computer Systems: A Programmer’s Perspective will teach you all the gory details of how source code gets turned into machine code.
The dearth of good C books is a bit of a bummer, but there may be a silver lining. I think many learners rely too much on books. It’s often more educational to poke around on your own. Read other people’s code. Examine open source projects. Ask others for help. And if you’re not sure how something works, do science!
If you’re wondering why the compiler didn’t warn about this, it’s because this happened in 1998. Back then, gcc didn’t warn about assignments in conditionals. Nowadays, any sane compiler will complain. How fortunate one is to learn C today. 🙂 ↩