Why Zig over C for Systems Programming
An experienced systems programmer explains why they prefer Zig over C for new projects, highlighting improvements like errdefer, safe slices, and comptime.
summary is enough The code comparisons clearly illustrate Zig's safety features over traditional C, though the arguments will be familiar to anyone following modern systems language debates.
summary
The author compares Zig and C to show how Zig solves common C pain points without introducing a garbage collector or losing low-level control. Key improvements include errdefer for cleanups without manual goto labels, slices that track their own lengths, and enforced error handling. While C retains unmatched ecosystem stability and ubiquity, Zig offers a safer and more ergonomic baseline for greenfield projects. The discussion highlights that many of these safety features are now achievable in modern C with strict toolchain configuration.
key points
- Zig replaces error-cleanup gotos with errdefer statements that automatically execute in reverse order upon failure.
- Slices carry length information, preventing off-by-one errors and unsafe string operations common in raw C pointers.
- The built-in zig cc toolchain provides out-of-the-box cross-compilation, integer overflow sanitizers, and seamless C interop.
who should read it
Systems programmers evaluating modern language alternatives to C for greenfield low-level projects.
discussion skeptical
consensus
Commenters note that many of Zig's listed advantages can be replicated in modern C using compiler sanitizers, attributes, and span types.
pushback
Some argue that language defaults matter because relying on optional tooling discipline fails at scale, while others criticize the article as generic content.
Zig is a nice language, but those articles always compare new languages against old-style C without use of modern tools. Most of the listed advantages you can have in C as well if you are willing to adopt modern tooling and style: signed overflow checking: sanitizers, errors you can not ignore: [[nodiscard]], slice type which know their size: variably-modified types or span types.
Defer will also appear in C compilers soon, but personally I still think goto-error handling is clearer.
(Rust has an advantage for temporal memory safety, but this does apply to Zig.)
It outlines how modern C tooling addresses several of the author's complaints, reframing the debate from absolute language limits to default behaviors.
Generated by an LLM from the article and thread. Check the sources before relying on it.