4 ms·
Ask HN: Good C codebases to read?
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://news.ycombinator.com/item?id=9896369
- informatimago 11y agogcc, postfix, fossil, a lot of major projects have good C code.
- infamouscow 11y agogcc is a good example of terrible C code.
- jotux 11y agoFossil 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/www/makefile.wiki 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.
- detaro 11y agoI think the last time this came up sqlite was recommended
- miguel250 11y agoI find https://github.com/antirez/redis https://github.com/antirez/redis one of the best C codebase to read.
- marvel_boy 11y agosqlite http://www.sqlite.org/docs.html http://www.sqlite.org/docs.html
- wkoszek 11y agoOne 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 11y agoThere is also an official mirror on Github. https://github.com/freebsd/freebsd https://github.com/freebsd/freebsd
- lastofus 11y agoRedis' src is very clean and easy to dive into. https://github.com/antirez/redis https://github.com/antirez/redis
- devbug 11y agoBoth Lua and LuaJit. https://github.com/LuaDist/lua https://github.com/LuaDist/lua https://github.com/LuaDist/luajit https://github.com/LuaDist/luajit
- wkoszek 11y agoLua'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.
- anywherenotes 11y agoAny good C++ codebases?