Topic
C Programming
C is the most widely used language for firmware. Sixteen short insights build up the C you need, starting with the compiler chain, with what changes on a microcontroller (MCU) and on a microprocessor (MPU). Each one is a 3–4 minute read with a diagram, C11 code that compiles without warnings, and the output it prints.
Read the first insightvoid poll_sensors(void);int main(void) { for (;;) { poll_sensors(); }}
Insights
-
From source to binary
Preprocess, compile, assemble and link: what each tool does.
-
Types and integer widths
int, stdint, sizeof, promotion and overflow: how wide is a number?
-
Operators and bit operations
Logical vs bitwise, shifts and masks: set, clear, toggle, test.
-
Control flow
if, switch and loops, and the super-loop that runs forever.
-
Functions, scope and storage
The call stack, pass by value, static and extern.
-
Pointers
Addresses, & and *, pointer arithmetic and fixed-address registers.
-
Arrays and strings
Fixed-size arrays, decay to pointers, and the terminating zero.
-
Structs, unions and bit-fields
Layout and padding, unions, bit-fields and register overlays.
-
The preprocessor and macros
#define, function-like macros, #if and their pitfalls.
-
volatile and const
Registers, interrupt flags and read-only data in Flash.
-
Memory layout
text, rodata, data, bss, heap and stack: where each variable lives.
-
Dynamic memory
malloc, free, fragmentation, and static pools instead.
-
Function pointers and callbacks
Dispatch tables, callbacks and the vector table.
-
Headers and multi-file projects
Declaration vs definition, include guards and private names.
-
enum, typedef and state machines
Named states, switch-based and table-driven state machines.
-
Undefined behaviour and endianness
UB traps the optimiser exploits, and byte order on the wire.