Ask HN: Books to learn advanced C programming
Hello,
I've recently been doing a lot of systems programming and low-level stuff. I'm hacking away on MIT's xv6 kernel for my OS course. I want to improve my C skills, and want to learn the limits of what can be done with C, the preprocessor etc. I'd be really grateful if some one could direct me to resources that would help me out in this regard.
I want to basically learn how to write robust, readable and production-quality C which doesn't crash to a segfault.
Also, is there a oft-used style guide for writing error-handling code in C?
Thank you.
12 comments
[ 3.1 ms ] story [ 37.0 ms ] thread[1] https://github.com/radare/radare2
http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp...
I also second the recommendation for Peter van der Linden's Expert C Programming for its masterful treatment of how C really functions, including the surprisingly frequent areas in which real-world constructs produce "undefined behavior" from the perspective of the C standard.
[1] http://www.amazon.com/Interfaces-Implementations-Techniques-...
Plus of course hacking on programs, most often various ersatz Emacs versions that would run on a PDP-11. I.e. something I really wanted to get working to my satisfaction.
http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf
http://www.leshatton.org/MISRA_comp_1105.html
http://www.leshatton.org/ISOC_subset1103.html
http://www.embedded.com/electronics-blogs/embedded-systems-d...
For the related topic of secure code, these books are good:
Mark Dowd. 2006. The Art of Software Security Assessment.
Robert Seacord. 2013. Secure Coding in C and C++, 2e.
For details on what is really going on inside C:
Paul Anderson. 1998. Advanced C: Tips and Techniques.
Kenneth Louden. 1997. Compiler Construction: Principles and Practice. Chapter 7.
For C gotchas and general good practices:
http://www.cs.tufts.edu/comp/40/reference/CTrapsAndPitfalls....
Allen Holub. 1995. Enough Rope to Shoot Yourself in the Foot.
P.J. Plauger. 1991. The Standard C Library. (It is partly a reference, but also has detailed discussion of the technical considerations faced in writing reliable code.)
Also, at least personally, I stick to 3 key basic rules in C/C++ (I have a lot more, but these are important):
Really solid and reliable code is usually way less complex then what you see in a lot of code bases. That doesn't mean it isn't a super complex problem getting solved, just that the reliability is gained by having simplicity at the lowest levels. As someone mentioned Doom is a good example of a solid code base that does some pretty complex things, but cleanly and simply overall.http://c-faq.com/
C Interfaces and Implementations: Techniques for Creating Reusable Software by David R Handon is another must check out.
[1] http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf