Advanced C (Pre-Kernel)
The last stretch before Phase 2: function pointers, linked lists, bitwise tricks, undefined behaviour, and the ring buffer — the classic UART-driver interview question.
The last stretch of Phase 1 before the kernel itself — seven chapters that stopped feeling like "C syntax" and started feeling like the actual material driver code is written in.
The seven chapters
- A — Function Pointers. Declaring, assigning, and calling through a pointer to a function — the mechanism behind every callback-based API.
- B — Linked Lists. Node structs, insert/search/delete, doubly linked variants, reversal, and the fast/slow pointer tricks for finding a middle or detecting a cycle.
- C — Bitwise Operations Deep Dive. Set/clear/toggle/test a single bit, extract or insert a multi-bit field, endianness, and the classic bit tricks like Kernighan's popcount.
- D — const, volatile, register, restrict. A second, deeper pass on const and volatile, plus the two rarer qualifiers.
- E — Inline Functions, Variadic, Compound Literals.
static inlineas a type-safe macro replacement, variadic functions, and compound literals. - F — C Standards & Undefined Behaviour. What actually changed across C89 through C17, and the real inventory of what counts as undefined behavior.
- G — Ring Buffer. Wraparound mechanics and the three ways to tell a full ring buffer apart from an empty one — the classic UART-driver interview question.
Where this lands in driver work
Function pointers (A) are the entire mechanism behind struct file_operations — a driver's .open/.read/.write/.ioctl are just function pointers the kernel calls through generically, without ever knowing which driver it's actually talking to. And the ring buffer (G) is the standard shape for a UART's RX buffer: the ISR pushes bytes in on one end, a read() call drains them from the other, and the whole thing has to work without either side stepping on the other.
Function Pointers
Declaration, assignment, calling through a pointer, typedef’d function types, arrays of function pointers, callback patterns.
Linked Lists
Node structs, insert head/tail, search, delete, free-all, doubly linked, reverse, find middle, detect cycle.
Bitwise Operations Deep Dive
Set/clear/toggle/test bit, extract/insert field, endianness, power-of-2 test, Kernighan popcount, byte/XOR swap.
const, volatile, register, restrict
A deeper pass on const and volatile, plus register and restrict.
Inline Functions, Variadic, Compound Literals
static inline as a type-safe macro replacement, va_list/va_start/va_arg, compound literals, designated initializers.
C Standards & Undefined Behaviour
C89–C17 differences, _Bool/stdbool, _Static_assert, the real UB inventory (signed overflow, null deref, OOB, strict aliasing, UAF), integer promotions, the -1 < 1U trap.
Ring Buffer
Wraparound mechanics, the three full/empty disambiguation strategies, and a byte ring buffer put/get — the UART driver interview classic.
Notes from readers
Comments — via GitHub