Strings and Arrays
Arrays, C strings, and hand-implementing the standard-library classics from scratch.
Arrays and C strings, and then at the end, actually hand-writing the standard-library functions I'd been calling for granted the whole time — that last chapter changed how I read every string function since.
The six chapters
- A — Array Fundamentals. Declaration, indexing, the fact that the size is fixed forever once declared, zero bounds checking, and decay the moment an array is passed to a function.
- B — Multidimensional Arrays. Row-major layout and how indexing a 2D array actually resolves to one flat block of memory underneath.
- C — C Strings. A string is just a
chararray with an agreed-upon ending — the null terminator — and most string bugs are really just forgetting that agreement exists. - D — String Library Functions.
strlen/strcpy/strcmpand friends, plus the sharp edges that make half of them genuinely dangerous to use carelessly. - E — Arrays vs Pointers. Where the two are close enough to be interchangeable, and the specific places —
sizeof, reassignment — where they very much are not. - F — Implement the Classics. Writing
my_strlen,my_strcpy/my_strncpy,my_strcmp,my_memcpy,my_memmove, andmy_atoiby hand instead of just calling them.
Where this lands in driver work
No bounds checking on arrays is exactly the same deal as touching hardware memory directly — nothing stops an off-by-one from writing past a buffer into whatever happens to sit next to it. Parsing a byte stream off a UART or a packet off a bus is, mechanically, the same array-walking discipline as chapter C and D, just with hardware instead of a text string on the other end.
Array Fundamentals
Declaration, indexing, fixed size, no bounds checking, decay on function call.
Multidimensional Arrays
Row/column layout and access patterns for 2D arrays.
C Strings
Null-terminated buffers and the bugs that come from forgetting the terminator.
String Library Functions
strlen/strcpy/strcmp and friends, and their sharp edges.
Arrays vs Pointers
Where the two are interchangeable and where they genuinely are not.
Implement the Classics
Hand-written my_strlen, my_strcpy/strncpy, my_strcmp, my_memcpy, my_memmove, my_atoi.
Notes from readers
Comments — via GitHub