# C Programming Langauge

- Page: https://shared.btbytes.com/p/c
- Date: 2020-01-14
- Tags: programming-language, c

## Why C?

"The Endurance of an Unmanageable Language" - [Some Were Meant for C](https://www.cl.cam.ac.uk/~srk31/research/papers/kell17some-preprint.pdf); via [ATS As a Systems Programming Language](http://blog.vmchale.com/article/ats-rust).

## Learning

- youtube lectures on [C programming by Prof Jerry Cain](https://www.youtube.com/watch?v=Ps8jOj7diA0&list=PLNjjx1hAv9u9bd-s_lx4ccwLanr2w6IBR), structured around the book Computer Systems: A programmer's Perspective by Bryant & O'Hallaron.
- [Charles Cabergs - YouTube](https://www.youtube.com/@cacharle)

## Tooling

- [post modern C tooling - draft 5](https://renesd.blogspot.com/2019/09/post-modern-c-tooling.html)
- [A Modern C Development Environment | Interrupt](https://interrupt.memfault.com/blog/a-modern-c-dev-env#visual-studio-code-dev-containers)

## Why not C?

[C Is Not a Low-level Language - ACM Queue](https://queue.acm.org/detail.cfm?id=3212479)

## Books

- [Learn C Programming With 9 Excellent Open Source Books - OSS Blog](https://www.ossblog.org/learn-c-programming-with-9-excellent-open-source-books/)
- [Learn C programming | Lulu's blog](https://lucidar.me/en/c-class/learn-c-programming/); 14 chapters with examples and quizzes.
- [comp.lang.c Frequently Asked Questions](http://c-faq.com/index.html)
- [C Craft](http://www-cs-students.stanford.edu/~blynn/c/) notes by  Ben Lynn on C vs many other languages.  "[C is the desert island language](http://www-cs-students.stanford.edu/~blynn/c/intro.html)"
- [Object Oriented C](https://www.cs.rit.edu/~ats/books/ooc.pdf), 1993 by [Axel-Tobias Schreiner](https://www.cs.rit.edu/~ats/books/index.html)

## People and blogs

- <https://c9x.me/> by [Quentin Carbonneaux](http://www.cs.yale.edu/homes/qcar/). [qbe](https://c9x.me/compile/) compiler backend etc.,
- [The Jim Roskind C/C++ Grammar](http://blog.robertelder.org/jim-roskind-grammar/)

# Important

- [cdecl](http://cdecl.org/); C gibberish ↔ English
* [~sircmpwn/cstyle](https://git.sr.ht/~sircmpwn/cstyle) -- style
  guidelines on the lines of "SHOULD" and "SHOULD NOT"s.

# C libraries

- [Better String library](http://bstring.sourceforge.net)
- [Valgrind](http://valgrind.org/)
- [zeromq](http://www.zeromq.org/)
- [lock-free data structure library](http://www.liblfds.org/)
- [uthash -- simple data structures](http://uthash.sourceforge.net/)
- [Compilers targetting C](https://github.com/dbohdan/compilers-targeting-c)
- [TrustInSoft/tis-interpreter: An interpreter for finding subtle bugs in programs written in standard C](https://github.com/TrustInSoft/tis-interpreter)

## Memory Management

- [Untangling Lifetimes: The Arena Allocator](https://www.rfleury.com/p/untangling-lifetimes-the-arena-allocator); making performant dynamic manual memory management in C feel almost like garbage collection by Ryan Fleury.
- [Malloc tutorial](https://danluu.com/malloc-tutorial/) by Dan Luu

## C programming practices

- [C Programming Substance Guidelines](https://github.com/btrask/stronglink/blob/master/SUBSTANCE.md) from the [Stronglink](https://github.com/btrask/stronglink) (a searchable, syncable, content-addressable notetaking system) project
- Lecture notes on [Practical Programming in C](http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/).
- [A rant on C](https://gist.github.com/btbytes/e2d8d27ea396bf5b4e74) (not by me)
- [a critique of "how not to c"](https://github.com/Keith-S-Thompson/how-to-c-response); Jan 2016.
- [how to c](https://matt.sh/howto-c); [HN](https://news.ycombinator.com/item?id=10864176) <q>Another interesting approach to learning C if you already know Python is to re-implement the C compiler described in this article. If you're looking for a way to learn 10 things while also learning C then this 500 line Python complier is A++.</q>


## Cool stuff

- [How I wrote a self-hosting C compiler in 40 days](http://www.sigbus.info/how-i-wrote-a-self-hosting-c-compiler-in-40-days.html)
- How to read C declarations.. say `int *(*func())();` -- [C Right-Left Rule (Rick Ord's CSE 30 - UC San Diego)](http://web.archive.org/web/20041204200613/http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html) --    "func is function returning pointer to function returning pointer to int".
- [Memory Allocation](https://samwho.dev/memory-allocation/) at samwho.dev -- intuitive visual guide on how memory allocation works step by step.
- [Writing a C compiler in 500 lines of Python](https://vgel.me/posts/c500/)
- [Writing a simple 16 bit VM in less than 125 lines of C | andreinc](https://www.andreinc.net/2021/12/01/writing-a-simple-vm-in-less-than-125-lines-of-c)

## Programming Language Theory

- [Subtleties of the ANSI/ISO C standard](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1637.pdf) by Robbert Krebbers, Freek Wiedijk of Radboud University Nijmegen.

> we argue that the C standard does not allow Turing complete
implementations, and that its evaluation semantics does not preserve
typing. Finally, we claim that no strictly conforming programs
exist. That is, there is no C program for which the standard can
guarantee that it will not crash.


## Discussions

-  Comments on [The cost of forsaking C | Hacker News](https://news.ycombinator.com/item?id=12641948)

## Safe C

[A Tour of Xr0 - Xr0](https://xr0.dev/learn)

> Xr0 is a new verifier for the C programming language that eliminates many classes of undefined behaviour, such as use-after-frees (of which double frees are a special case), dangling and null pointer dereferences, memory leaks and the use of uninitialised memory. Most importantly, we believe Xr0 is on a clear trajectory towards enabling programming in C with no undefined behaviour whatever.
