← C ProgrammingC PROGRAMMING 1.7

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 inline as 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.

Notes from readers

Comments — via GitHub