Preprocessor and Compilation
Macros, conditional compilation, multi-file builds, and the kernel-style macro patterns that show up in real driver source.
The chapter about everything that happens to C source before the actual compiler sees it, how a project turns into more than one file without falling apart, and the specific macro tricks the kernel leans on constantly.
The six chapters
- A — Preprocessor Directives.
#define,#include, and the rest of the directive set — all pure text substitution before real compilation even starts. - B — Conditional Compilation.
#ifdef/#ifndef/#iffor code that only exists on certain platforms or builds. - C — Multi-File Compilation. Header guards, the declaration-vs-definition split, and how separate
.cfiles actually become one program. - D — Makefiles. Targets, dependencies, and a build rule set that only rebuilds what actually changed.
- E — Linking & Libraries. Static vs dynamic linking, and how the linker resolves a function call to an actual address.
- F — Kernel-Style Macros & GCC Extensions.
container_of,ARRAY_SIZE, type-safe min/max,offsetof, flexible array members,likely/unlikely, and the GCC extensions that make them possible.
Where this lands in driver work
Chapter F is basically a direct preview of reading real kernel source — container_of in particular shows up everywhere a callback only gets handed a pointer to one struct member and needs to recover the whole containing struct from it. Conditional compilation (B) is exactly how the same driver source supports multiple SoC variants or build configs without forking the file.
Preprocessor Directives
#define, #include, and the rest of the directive set.
Conditional Compilation
#ifdef/#ifndef/#if and platform-guarded code.
Multi-File Compilation
Header guards, declarations vs definitions, separate compilation.
Makefiles
Targets, dependencies, and a basic build rule set.
Linking & Libraries
Static vs dynamic linking and how the linker resolves symbols.
Kernel-Style Macros & GCC Extensions
container_of, ARRAY_SIZE, type-safe min/max, offsetof, flexible array members, likely/unlikely, GCC builtins, statement expressions.
Notes from readers
Comments — via GitHub