When Things Go Wrong: Error Handling Strategies in C

Post 6 of the Dynamic Arrays in C series · Full source code on GitHub The Error You’ve Been Ignoring Every function we’ve written so far can fail. array_create calls malloc, twice. array_push calls realloc when the buffer is full. Every one of those calls can return NULL, and every time it does, we’ve printed a message to stderr and returned -1 or NULL. That’s the extent of our error handling: we report the problem and hope the caller notices. ...

June 11, 2026 · 18 min · pablo

The Growth Factor Debate: 1.5x, 2x, or Something Else?

Post 3 of the Dynamic Arrays in C series · Full source code on GitHub The Choice We Skipped In Post 2, we solved the “array is full” problem by doubling the capacity on every realloc. We wrote new_cap = old_cap * 2, watched the buffer grow from 2 to 4 to 8 to 16, and moved on. Three reallocations for 12 elementsm, pretty good. But we never justified the number 2. Why not 1.5? Why not 3? Why not just add 100 slots every time? ...

June 1, 2026 · 17 min · pablo

Growing Pains: realloc and Automatic Capacity Management

Post 2 of the Dynamic Arrays in C series · Full source code Where We Left Off In Post 1 we built an array that does three things: allocate a fixed buffer, push integers into it, and free everything when we’re done. It works, until it doesn’t. The moment the user pushes one element more than the initial capacity allows, array_push returns -1 and refuses to cooperate. The array is full and there’s nothing we can do about it. ...

May 28, 2026 · 14 min · pablo