Hacker Timesnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Good C codebases to read?
19 points by golergka on July 16, 2015 | hide | past | favorite | 12 comments
What is good but not super-complex C codebases that can be used to learn about proper practices used in modern complex projects?

Inspired by this thread: https://hackertimes.com/item?id=9896369



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

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/


There is also an official mirror on Github. https://github.com/freebsd/freebsd


I find https://github.com/antirez/redis one of the best C codebase to read.


I think the last time this came up sqlite was recommended



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.


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

https://github.com/antirez/redis



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


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...

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


gcc is a good example of terrible C code.


Any good C++ codebases?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: