Hacker News new | past | comments | ask | show | jobs | submit login

I want to read some good C code. Can anyone recommend me a project that's not too big? I'm thinking of skimming some of these core linux libraries [0]

[0] http://linuxfromscratch.org/lfs/view/stable-systemd/chapter0...




Late to this, & am not really a C programmer (longtime bash & java/scala etc, and studying Rust now), but for exemplary C I think of OpenBSD core utilities first (ie, not ports & packages), given their ongoing auditing for security and correctness. The code can be browsed online, or installed as part of a basic system. I found it interesting to browse starting with some smaller utilities like echo and ls.

Resources:

https://cvsweb.openbsd.org/src/bin/

https://cvsweb.openbsd.org/

https://github.com/openbsd

https://www.openbsd.org/anoncvs.html

https://www.openbsd.org/ (where I got the above links, on the left side under "Getting Source")


(just to improve my previous accuracy where I mentioned scala & rust, though it's too late to edit: ...and C++ and many other things .)


If you’re going to try read along with Robert Love’s Linux Kernel Development. Even outdated its the best guide I’ve found. That said I’m kind of a C beginner so take with a grain of salt. I frequently get derailed by the Macros, architectural stuff etc in the kernel and can’t figure out what exactly the code is doing.


You might want to read '500 lines or less'[1]. Here you not only read the code but also see it in the context of the 'bigger picture' of the design / architecture / problem being solved.

[1] https://www.aosabook.org/en/index.html


The FreeBSD core utilities are reasonably short:

https://github.com/freebsd/freebsd/tree/master/bin


redis is very good. Also, any suckless project is very readable. I liked Lua code too.

I'm not a C programmer but these projects have this Quality in common that transcends the programming language (I think). Opinions?


lmdb is one that comes off the top of my head.

But even that the main file is 11000+ lines of code.




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

Search: