
Ask HN: Good C codebases to read? - golergka
What is good but not super-complex C codebases that can be used to learn about proper practices used in modern complex projects?<p>Inspired by this thread: https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=9896369
======
wkoszek
One of the very good sources of knowledge is the FreeBSD code base. You can
check it out from Subversion, and have a complete operating system in the .c
and .h form. This is actually how I gained the proficiency in C. It exposes
you to industry-grade C (e.g.: you'll learn about bits which are hard in C but
are being used actively) Also if you ever get interested in operating systems,
FreeBSD gives you a very nice transition, since both programs and the kernel
are in the same repo.

To check out the FreeBSD source code, you can do:

svn co [https://svn.freebsd.org/base/head](https://svn.freebsd.org/base/head)

And if you want to know how 'cat' is implemented, go to bin/cat/.

Same for 'ls', 'find' etc..

Other than that, early source code of UNIX gurus is very good too. Check out
the Plan 9 project from Bell Labs. It has a very clean code too:

[http://plan9.bell-labs.com/sources/plan9/sys/src/](http://plan9.bell-
labs.com/sources/plan9/sys/src/)

~~~
sigjuice
There is also an official mirror on Github.
[https://github.com/freebsd/freebsd](https://github.com/freebsd/freebsd)

------
miguel250
I find [https://github.com/antirez/redis](https://github.com/antirez/redis)
one of the best C codebase to read.

------
detaro
I think the last time this came up sqlite was recommended

------
devbug
Both Lua and LuaJit.

[https://github.com/LuaDist/lua](https://github.com/LuaDist/lua)

[https://github.com/LuaDist/luajit](https://github.com/LuaDist/luajit)

~~~
wkoszek
Lua's C code base is fairly complex. I don't recommend it to a people willing
to study C more. When I attempted to embed Lua into the FreeBSD's loader I
expected it to be much easier. But when things went wrong and I had to jump
and understand Lua internals, it too a while.

------
lastofus
Redis' src is very clean and easy to dive into.

[https://github.com/antirez/redis](https://github.com/antirez/redis)

------
marvel_boy
sqlite [http://www.sqlite.org/docs.html](http://www.sqlite.org/docs.html)

------
informatimago
gcc, postfix, fossil, a lot of major projects have good C code.

~~~
jotux
Fossil is a high quality codebase but a little odd in many respects. For
example, the build process runs three custom preprocessors to generate header
files: [http://fossil-
scm.org/index.html/doc/74836bc8ae09edd152d8/ww...](http://fossil-
scm.org/index.html/doc/74836bc8ae09edd152d8/www/makefile.wiki)

For a beginner looking for idiomatic C code I wouldn't really recommend it as
something to study.

------
anywherenotes
Any good C++ codebases?

