[Beginner] — Why a language from 1972 is still under everything, and the four-stage pipeline that turns your text into a binary.

Source: [reference] — no C project in this vault yet. See Project Ideas.

Why C still matters

C is small — the entire language fits in a short book — and it maps almost directly onto how a machine works. That combination made it the substrate everything else got built on.

Concretely, C is still what you’re standing on:

  • Every operating system kernel — Linux, Windows, macOS/XNU, and every RTOS
  • Every language runtime — CPython, the JVM’s HotSpot, V8, the Go runtime, Ruby, PHP
  • The databases — SQLite, PostgreSQL, MySQL, Redis
  • The infrastructure — nginx, OpenSSL, curl, git, ffmpeg, SQLite again
  • Embedded and firmware, near-universally → hardware/
  • The ABI everything speaks. When Rust, Python, or Java calls into another language, it speaks C’s calling convention. C is the lingua franca of FFI — which is why Rust’s FFI note is entirely about C compatibility.

So even if you never ship C, you read it: to understand a kernel bug, to debug a library, to know what your runtime is doing.

What you’re signing up for

The honest framing, especially having just done Rust:

C gives you no safety at all. No bounds checking, no ownership, no lifetimes, no type safety across a void*, no null protection, no automatic memory management, no exceptions, no destructors, no strings, no collections, no modules, no namespaces.

There is you, and there is what the machine does.

That’s why ~70% of serious security vulnerabilities in large C/C++ codebases are memory-safety bugs — the figure Microsoft and Google both publish. Not because C programmers are careless, but because the language provides no mechanism to be careful with, and humans do not maintain perfect vigilance across a million lines. → Exploits

The correct attitude: learn C to understand the machine and read the world’s infrastructure. Reach for it for new projects only when you genuinely need it — embedded targets with no Rust toolchain, existing C codebases, or a stable ABI boundary.

The compilation pipeline

C compilation is four distinct stages. Knowing them is what makes linker errors readable instead of terrifying.

hello.c
   │
   │  1. PREPROCESS   cpp        — text substitution: #include, #define, #if
   ▼
hello.i   (still C, but expanded — often 20,000+ lines from one #include <stdio.h>)
   │
   │  2. COMPILE      cc1        — parse, type-check, optimise, emit assembly
   ▼
hello.s   (assembly for your target architecture)
   │
   │  3. ASSEMBLE     as         — assembly → machine code
   ▼
hello.o   (OBJECT FILE — machine code with unresolved symbols)
   │
   │  4. LINK         ld         — resolve symbols across object files and libraries
   ▼
hello     (executable)

You can stop at any stage and look:

gcc -E hello.c -o hello.i     # preprocess only — see what #include actually pasted in
gcc -S hello.c -o hello.s     # stop after compiling — read the assembly
gcc -c hello.c -o hello.o     # stop after assembling — one object file
gcc hello.o -o hello          # link
gcc hello.c -o hello          # all four

gcc -E on a file that includes <stdio.h> is worth running once, just to see that #include is literally pasting a file in. It explains a lot of C’s design.

Why stages 3 and 4 are separate

Each .c file compiles independently into a .o. The compiler sees one file and nothing else — this is the translation unit, and it’s the single most important concept in the next note.

Separate compilation is why:

  • Changing one .c file only recompiles that file
  • The compiler can’t check calls across files (it hasn’t seen the other file) — headers exist to fix this
  • Linker errors are a different species from compiler errors
undefined reference to `foo'          ← LINKER: nobody defined foo. Missing .c file or -l flag
multiple definition of `foo'          ← LINKER: two translation units both defined it
implicit declaration of function      ← COMPILER: you called foo without declaring it. Missing #include

Reading which stage failed tells you where to look. A compiler error is in your code; a linker error is in your build.

Compiling properly

gcc -std=c17 -Wall -Wextra -Wpedantic -g -O2 main.c -o main
FlagDoes
-std=c17pin the language standard (c99, c11, c17, c23)
-Wall -Wextraturn on warnings — C’s defaults are far too quiet
-Wpedanticwarn on non-standard extensions
-Werrorwarnings become errors; correct for CI
-gdebug symbols, for gdb
-O0 / -O2 / -O3optimisation level; -O0 for debugging
-fsanitize=address,undefinedruntime bug detection → Debugging and Tooling
-I dirwhere to look for headers
-L dir -lfoolink libfoo from dir

-Wall -Wextra is not optional. C compiles a shocking amount of broken code silently by default. Most of the classic beginner disasters produce a warning that nobody enabled.

Hello, world

#include <stdio.h>
 
int main(void) {
    printf("Hello, world!\n");
    return 0;
}
  • #include <stdio.h> — a preprocessor directive that pastes the file in. <> searches system paths, "" searches your project first.
  • int main(void) — void explicitly means “no parameters”. Bare main() means “unspecified parameters”, which is different and worse. Use int main(void) or int main(int argc, char **argv).
  • return 0 — 0 is success. Non-zero is failure, and that’s what a shell’s $? and && read → Bash Scripting.
  • \n matters. stdout is line-buffered to a terminal; without a newline your output may not appear when you expect.

Static vs dynamic linking

gcc main.c -o main                    # dynamic by default — links libc at RUN time
gcc -static main.c -o main            # static — everything baked in, big binary
ldd main                              # what shared libraries does this need?

Dynamic linking means the binary depends on libc.so existing on the target machine, at a compatible version. That’s the “works on my machine, glibc version mismatch in the container” problem, and it’s the reason Go’s static binaries are considered such a deployment advantage.

The standards

StandardNotable
C89/C90the old baseline; declarations must precede statements
C99// comments, declare-anywhere, stdint.h, bool, VLAs, designated initialisers
C11_Static_assert, atomics, threads, anonymous structs
C17bug fixes only
C23nullptr, constexpr, typeof, #embed, bool as a keyword

Default to C11 or C17. C99 is the floor for anything modern; C89 only for genuinely ancient targets.


↑ Back to C