This is a read-only archive!


I got K&R (the ANSI C version) as one of the going-away presents from my current / last job, and I just finished reading it.

A lot of what's in the book is sort of review for me now but there were some things I'd never seen before. For example in the book they like to put function declarations inside other functions instead of globally at the top of the file. I never even thought to do that, for whatever reason. I also was unfamiliar with some of the more obscure corners of the C language, like register variables. Apparently the book was just written when ANSI was becoming / had become standard, so it's also fun to get a small glimpse at how things were before that. (They looked to be a mess.)

It's definitely the kind of book I wish I'd have had back in high school when I was just learning to program. For example the very straightforward explanation of how file handles work in Unix systems is nice and clear and is one of those things that I was wondering about for years in my youth: How is it that I can access stdout, stdin and stderr without doing anything? Where are those handles coming from? They seemed to be there like magic, and I never knew if it was always safe to assume that I'd have those available in every programming language I used on every OS I tried, or what. Likewise, I remember in the vast majority of programs I wrote in high school, I would trip up over I/O buffering. K&R explains that really well also.

Things that everyone "just knows" and assume that you also know are the biggest pitfall in learning computers, to me. Unix / Linux seems chock-full of that kind of crap. How do you know to try --help or man to figure out how to use a command? How do you know that ~ means "home directory"? How do you know that you start X via startx? If you don't know those things, short of asking someone else, it's very hard to discover how to do them. For people who know how to do it, it's such common knowledge that no one bothers to write it down. It's a huge leap that people have to make when first learning Linux or programming in general. A book like K&R is great because it gives you a starting point, and they explain pretty much everything. "Comprehensive" is probably the word I'm looking for.

In any case, as a rule, I detest low-level programming, of the "bit-twiddling" form. But there's obviously a need to know how to do it at times, and I think if I was more in the practice of falling back to C or other low-level languages when the problem at hand demanded it, I would probably be a better programmer. So I'm glad to try to learn more of it.

September 12, 2007 @ 7:07 AM PDT
Cateogory: Book Reviews
Tags: K&R, Books, C


Steven Oliver
Quoth Steven Oliver on September 12, 2007 @ 12:23 PM PDT

If I'm not mistaken, the "register" keyword is no longer used. I mean, you can use it, it will compile and link, but it won't make any difference.

Quoth Brian on September 12, 2007 @ 3:22 PM PDT

I imagine it's massively platform- and compiler-dependent whether the register keyword does anything or not, but I wouldn't be surprised if it did nothing in many cases given how different computers are today than when K&R wrote the book. (K&R says that it's always only a hint at best anyways and all compilers are free to ignore the register keyword, but even if the compiler ignores it you can never take the address of a "register" variable.) GCC 4.2 has this to say:

It doesn't look like ANSI C though.

(Also I have little to no idea what I'm talking about.)