Hello,<p>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.<p>I want to basically learn how to write robust, readable and production-quality C which doesn't crash to a segfault.<p>Also, is there a oft-used style guide for writing error-handling code in C?<p>Thank you.
For good practices in writing high-reliability C, look at these:<p><a href="http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf" rel="nofollow">http://lars-lab.jpl.nasa.gov/JPL_Coding_Standard_C.pdf</a><p><a href="http://www.leshatton.org/MISRA_comp_1105.html" rel="nofollow">http://www.leshatton.org/MISRA_comp_1105.html</a><p><a href="http://www.leshatton.org/ISOC_subset1103.html" rel="nofollow">http://www.leshatton.org/ISOC_subset1103.html</a><p><a href="http://www.embedded.com/electronics-blogs/embedded-systems-design-magazine-archive/4216555/Embedded-Systems-Design--May-2011" rel="nofollow">http://www.embedded.com/electronics-blogs/embedded-systems-d...</a><p>For the related topic of secure code, these books are good:<p>Mark Dowd. 2006. The Art of Software Security Assessment.<p>Robert Seacord. 2013. Secure Coding in C and C++, 2e.<p>For details on what is really going on inside C:<p>Paul Anderson. 1998. Advanced C: Tips and Techniques.<p>Kenneth Louden. 1997. Compiler Construction: Principles and Practice. Chapter 7.<p>For C gotchas and general good practices:<p><a href="http://www.cs.tufts.edu/comp/40/reference/CTrapsAndPitfalls.pdf" rel="nofollow">http://www.cs.tufts.edu/comp/40/reference/CTrapsAndPitfalls....</a><p>Allen Holub. 1995. Enough Rope to Shoot Yourself in the Foot.<p>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.)
I suggest C Interfaces and Implementations: Techniques for Creating Reusable Software by David Hanson.[1] It focuses on helpful engineering practices for reliably and efficiently implementing algorithms in C.<p>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.<p>[1] <a href="http://www.amazon.com/Interfaces-Implementations-Techniques-Creating-Reusable/dp/0201498413" rel="nofollow">http://www.amazon.com/Interfaces-Implementations-Techniques-...</a>
"Deep C Secrets" is quite good.<p><a href="http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp/0131774298" rel="nofollow">http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp...</a>
Of course there is the C programming language k&r and also Expert C programming which kind of cool also, but if you want to make really great software and write great code, then your only is not books but real OSS, go write some small project, improve it, present it to community and have it criticized , and so on in a loop, look for big projects source and learn from them, one fairly interesting project is radare2[1], it's a really cool project, please feel free to choose but look at projects already made and try to understand, you will learn a bunch from doing that.<p>[1] <a href="https://github.com/radare/radare2" rel="nofollow">https://github.com/radare/radare2</a>
Since it has yet to be mentioned yet, I'll suggest Modern C by Jens Gustadt [1]. The book itself starts from basics and works up, but I found it to be much more reliable and filled with more practical advice than the common K&R recommendation. Section / Level 4 is not quite in it's final form yet; however the book is mostly complete and gives a lot to think about. I suggest working through it, even if you skip the first few levels because of your base knowledge.<p>[1] <a href="http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf" rel="nofollow">http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf</a>
Expert C Programming: Deep C Secrets bu Peter Van Der Linden is a classic and must see.(<i></i><i>Highly recommended</i><i></i>)<p>C Interfaces and Implementations: Techniques for Creating Reusable Software by David R Handon is another must check out.
Start writing every project, except web projects in C. You'll be an expert in a few years. You'll get really good at string handling. You'll start to "think in bytes".
_Write Portable Code_ by Brian Hook is excellent. Under the guise of teaching the writing of portable code, he teaches you to write good code, just as you describe.
The comp C faq is a good place once you have a little bit of C experience.<p><a href="http://c-faq.com/" rel="nofollow">http://c-faq.com/</a>