C for People Who Already Know How to Code
C for People Who Already Know How to Code
This is a crash course in the parts of C that are easy to get wrong even after you already know the syntax. It assumes you can program in Go, Java, JavaScript, Rust, Python, whatever, and skips past for loops and function declarations straight to the stuff that actually breaks production code.
C's syntax is small enough to learn in an afternoon. What takes longer, and what this course is actually about, is the list of things the language lets you do that it does not check for you: reading past the end of an array, using a value before it's initialized, letting an integer wrap around when you meant it not to. None of that raises an exception. Most of it compiles clean, runs fine on your machine, and fails somewhere else, later, differently.
What makes C different from the language you already know
- No bounds checking.
arr[10]on a 10-element array is not an exception, it's an address the language will happily compute and let you write to. - No garbage collector. Every
mallocis a debt; nobody pays it but you. - The compiler assumes undefined behavior never happens and optimizes on that assumption, not "probably safe" but actively hostile to code that depends on UB behaving a particular way.
- Types are a compile-time convenience the runtime has mostly forgotten about by the time your program executes.
Everything in this course exists because it broke something for someone. Treat each section as a bug report, not trivia.
Try it yourself: confirm your toolchain before going further›
Compile this with warnings turned all the way up, and don't move on until it builds clean:
gcc -Wall -Wextra -Wpedantic -g -o hello hello.c#include <stdio.h>
int main(void) {
printf("hello, undefined behavior\n");
return 0;
}Keep -Wall -Wextra -Wpedantic on for every example in this course. Several of them are designed to trigger a warning, and that warning is half the lesson.