4 ms·
"The C Programming Language", commonly referred to as just "K&R", is probably one of the best introductions to a programming language ever written. It's short,
by emerose 17y ago
"The C Programming Language", commonly referred to as just "K&R", is probably one of the best introductions to a programming language ever written. It's short, clear, and concise — even today, 31 years after its first publication, it should be your first stop: http://en.wikipedia.org/wiki/The_C_Programming_Language_(book) http://en.wikipedia.org/wiki/The_C_Programming_Language_(boo...
As previous commenters have said, don't worry about the details early on. Advanced pointer arithmetic tricks and the like are to C what zany metaprogramming tricks are to Ruby: dangerous, and almost always a bad idea — except in those few cases where they're exactly what you need. For your first pass, you can ignore anything that's not obvious. You probably won't need it anyway, and you'll pick the truly important things up with time…
Code on UNIX, preferably Linux, using CLang and a simple text editor to start. The Windows APIs are just plain confusing for beginners, and OS X adds some wrinkles to the compilation process that it's better not to worry about in the beginning. Linux isn't as austere as some of the BSDs, but that makes it an easier platform to learn on. Similarly, while GCC is more common than CLang, CLang has a bunch of features — actually useful error messages, for example — that make it much much easier to deal with. Fancy IDEs like XCode and Eclipse have their place, but are more complicated than they should be for "hello, world"-type exploration. All you really want is syntax highlighting…
Since it sounds like you're coming from Ruby, check out the FFI project: http://github.com/ffi/ffi http://github.com/ffi/ffi FFI makes it reasonably easy to call C from Ruby, meaning you can build scaffolding in a language you're comfortable with while you focus on particular bits of C code. Similarly, it's not worth trying to learn the arcana of the C tool stack — make, autotools, etc — all at once, especially if you already know Rake.
Read other people's code. It's probably better to stick to smaller projects at first, especially reasonably modern ones which haven't gone too far off the deep end with the optimization. I don't have any great pointers here, unfortunately — the only thing that comes to mind is that (C) Python has some really nice, well-commented code and .txt files in its source tree, and that MRI Ruby is horrible. The libev API also strikes me as a good example at the moment — but that's probably at least partially because I've been staring at it so much recently…
Once you're feeling reasonably literate, the next step is to read some algorithms and data structures books. It's both a strength and a weakness of C that you essentially always end up implementing your own; even if you don't end up writing a lot of C code, getting a solid footing (or refresher course) in these will help make you a better programmer. After that, you can probably read code with the best of them. If you're still looking for more, I'd suggest maybe "UNIX Network Programming" by Stevens, Fenner, and Rudoff (a good introduction to the sockets API); or "Modern Operating Systems" by Tanenbaum … really, it just depends on what you're interested in.
-sq
- hga 17y agoGood advice, including using clang instead of gcc. To amplify on my advice WRT to K&R, if you bounce when you hit the arrays and pointers chapter, try another resource (maybe ask someone for help), that chapter just didn't work for me. Then again, pointers and recursion are the two basic hard concepts one needs to learn at this level (see Joel Spolsky on The Perils of Javaschools: http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html http://www.joelonsoftware.com/articles/ThePerilsofJavaSchool...) Good luck!