In light of the recent OpenSSL rant (http://news.ycombinator.com/item?id=1680337): what are some open source projects written in C which are particularly well-written?<p>I can give one example: I was very pleasantly surprised by the experience of cold-reading the BerkeleyDB source (trying to explain some very odd observed behavior) a few years ago. The code was laid out in a sensible way, such that I could find what I needed reasonably quickly. It was generally clear and straightforward to read, and the few places with "tricky" code were very nicely commented -- including the source of the odd behavior I was hunting for.<p>Are there other examples of great, readable C code out there?
In the past, I've found the code for SQLite to be brilliantly clear: <a href="http://sqlite.org" rel="nofollow">http://sqlite.org</a><p>Going further, I'd suggest that most large successful projects in C have clear code that is worthy of study. It's some corollary of the anthropic principle --- if the code wasn't clear, it would never have survived to become successful.<p>This may only apply to the core of these projects (written by experts) than to the periphery (written by learners). But you might be surprised by how readable the central code is for Apache, Linux, Glibc, Mysql, Perl, Python, etc.
I would recommend David R. Hanson's book <i>C Interfaces and Implementations</i>. It is an extremely well documented library and shows you how to design APIs properly.<p><a href="http://www.amazon.com/Interfaces-Implementations-Techniques-Creating-Reusable/dp/0201498413/" rel="nofollow">http://www.amazon.com/Interfaces-Implementations-Techniques-...</a>
Do you mean something like this?<p><pre><code> main(l
,a,n,d)char**a;{
for(d=atoi(a[1])/10*80-
atoi(a[2])/5-596;n="@NKA\
CLCCGZAAQBEAADAFaISADJABBA^\
SNLGAQABDAXIMBAACTBATAHDBAN\
ZcEMMCCCCAAhEIJFAEAAABAfHJE\
TBdFLDAANEfDNBPHdBcBBBEA_AL\
H E L L O, W O R L D! "
[l++-3];)for(;n-->64;)
putchar(!d+++33^
l&1);}
</code></pre>
(source: <a href="http://www.ioccc.org/years.html#1992_westley" rel="nofollow">http://www.ioccc.org/years.html#1992_westley</a>)
The Lua interpreter (pure ANSI C), both the core VM and the public C API for modules are well written.
<a href="http://www.lua.org/" rel="nofollow">http://www.lua.org/</a>
In most nontrivial projects, C is used to solve problems that are worse being solved with other platforms: targeting the biggest possible platform independence but caring about performance. So you can't compare the "beauty" of something that is supposed to run on my 50 USD router with 32 MB with something that has not much to do (measuring CPU and memory use) and has the luxury to be compiled only by a few compilers.<p>Another problem is that a lot projects "grow" without any vision. Once you understand that, you'll find that most of the successful C projects didn't have much more choice, more because of the history of them than anything else.<p>However when you have the full control of the platform and have a small numbers of the developers with a good taste (you control the OS and the compiler too) you can maintain "beauty" consistently. In this regard, I suggest you to enjoy Plan 9 sources!<p><a href="http://plan9.bell-labs.com/wiki/plan9/Sources_repository/index.html" rel="nofollow">http://plan9.bell-labs.com/wiki/plan9/Sources_repository/ind...</a>
I'm a fan of parts of the BSD kernel myself. My first exposure was through the book "The Design and Implementation of the FreeBSD Operating System". Then again, dorking around in kernels and the like hold some interest for me.
i really liked the redis codebase. not sure if its changed much since it became a much bigger project, but back when it was mainly @antirez, it was some of the cleanest code i've ever read.