October 25, 2026

I recently started writing C again for the first time since 2018, and handling errors has been an especially difficult adjustment coming from languages like Go and Zig that coddle me with their wonderful defer and errdefer. Then I read some emails from John Carmack on inlined code that gave me an epiphany on writing cleaner error handling code, and now I want to share it with the world.

But First Let’s Defer

I write Go all day at my dayjob, and error handling is pretty trivial. When there’s an error we wrap it and bubble it up, and let some top dog up the call stack figure out what they want to do with it. If there is resource cleanup involved, it’s made easy with defer: