Skip to content

Zig vs C, Rust & Go

If you’re looking at Zig, you’ve probably also looked at C, Rust or Go, and you want to know what Zig does differently before you spend weekends on it. This page gives you a straight answer: the same small program in all four languages, what each one is good at, a table side by side, and the honest downsides of Zig. Nobody here is the “winner”. They make different trade-offs, and the right pick depends on what you’re building.

Zig wants to be a better language for the jobs C does today: operating systems, games, embedded devices, tools, libraries other languages call. It keeps C’s directness (you control memory, nothing runs behind your back) and fixes the parts that hurt in C: no preprocessor, real error handling, slices that know their length, safety checks while you develop, and a build system and cross-compiler in the box.

The rule Zig repeats most is no hidden control flow: if a line doesn’t look like a function call, it isn’t one. There are no destructors running at the end of a scope, no operator overloading and no exceptions. The official overview explains the thinking behind that.

Here’s one small task: add up a list of numbers that arrive as text, and report it if one of them isn’t a number. It shows how each language handles errors, which says a lot about its personality.

Zig:

const std = @import("std");
fn sum(texts: []const []const u8) !i64 {
var total: i64 = 0;
for (texts) |text| {
total += try std.fmt.parseInt(i64, text, 10);
}
return total;
}
pub fn main() void {
const inputs = [_][]const []const u8{
&.{ "10", "20", "12" },
&.{ "10", "oops" },
};
for (inputs) |texts| {
if (sum(texts)) |total| {
std.debug.print("sum: {d}\n", .{total});
} else |err| {
std.debug.print("error: {t}\n", .{err});
}
}
}

Output:

sum: 42
error: InvalidCharacter

The !i64 return type means “an i64 or an error”. try passes an error up to the caller, and the caller has to deal with it: the compiler won’t let you ignore it. Don’t worry about every symbol yet; Zig Errors explains them later.

C:

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
/* Returns 0 on success and stores the result in *total, -1 on bad input. */
int sum(const char **texts, size_t count, long *total) {
*total = 0;
for (size_t i = 0; i < count; i++) {
char *end;
errno = 0;
long n = strtol(texts[i], &end, 10);
if (errno != 0 || end == texts[i] || *end != '\0') return -1;
*total += n;
}
return 0;
}
int main(void) {
const char *good[] = {"10", "20", "12"};
const char *bad[] = {"10", "oops"};
long total;
if (sum(good, 3, &total) == 0) printf("sum: %ld\n", total);
if (sum(bad, 2, &total) != 0) printf("error: bad number\n");
return 0;
}

Output:

sum: 42
error: bad number

C has no error type, so the function returns a status code and writes the answer through a pointer. Checking strtol properly takes three conditions. Nothing forces the caller to look at the -1, and the array lengths travel separately from the arrays.

Rust:

use std::num::ParseIntError;
fn sum(texts: &[&str]) -> Result<i64, ParseIntError> {
let mut total = 0;
for text in texts {
total += text.parse::<i64>()?;
}
Ok(total)
}
fn main() {
for texts in [&["10", "20", "12"][..], &["10", "oops"][..]] {
match sum(texts) {
Ok(total) => println!("sum: {total}"),
Err(err) => println!("error: {err}"),
}
}
}

Output:

sum: 42
error: invalid digit found in string

Rust’s Result and ? are very close to Zig’s error union and try. The difference is that a Rust error is a full value (here a ParseIntError with a message), while a Zig error is just a name like InvalidCharacter.

Go:

package main
import (
"fmt"
"strconv"
)
func sum(texts []string) (int64, error) {
var total int64
for _, text := range texts {
n, err := strconv.ParseInt(text, 10, 64)
if err != nil {
return 0, err
}
total += n
}
return total, nil
}
func main() {
for _, texts := range [][]string{{"10", "20", "12"}, {"10", "oops"}} {
total, err := sum(texts)
if err != nil {
fmt.Println("error:", err)
continue
}
fmt.Println("sum:", total)
}
}

Output:

sum: 42
error: strconv.ParseInt: parsing "oops": invalid syntax

Go returns the error as a second value, and you check it with if err != nil. It’s explicit like Zig, with more typing, and the compiler doesn’t stop you from ignoring an error you assigned to _.

All four were compiled and run for this page (Zig 0.17.1, gcc 13, Rust 1.97, Go 1.24).

Zig and C sit at the same level: no garbage collector, no runtime to speak of, direct control of memory. What Zig adds is mostly guard rails and tools: slices with a length instead of bare pointers, errors the compiler makes you handle, comptime instead of macros, runtime checks for out-of-bounds and overflow in debug builds, and one zig command that builds, tests and cross-compiles. What C has is fifty years of code, compilers for every chip ever made, a stable standard, and every operating system’s API written in it.

The nice part is you don’t have to choose all at once. Zig compiles C, calls C directly and can be called from C, so many people start by adding Zig to a C project. Read Zig for C Developers for the details side by side.

Rust and Zig are both modern systems languages without a garbage collector, and they’re often compared. The big difference is how they keep memory safe. Rust’s borrow checker proves at compile time that you never use freed memory or share data unsafely between threads. That guarantee is real and valuable, and it costs learning time and sometimes a fight with the compiler. Zig doesn’t have a borrow checker: you get runtime checks in debug and safe builds, a testing allocator that catches leaks and double frees, and the rest is on you.

Zig is a much smaller language, so there’s less to learn, and comptime covers what Rust spreads over generics, traits and macros. Rust is stable (1.0 came out in 2015) with a large package ecosystem. More in Zig for Rust Developers.

Go is a different kind of tool. It has a garbage collector and a runtime with goroutines built in, and it’s designed to make teams productive at writing network services. Zig has neither: you manage memory with allocators and choose your own way to run things at the same time. In exchange, Zig programs have no GC pauses and no runtime, so they fit places Go doesn’t: kernels, microcontrollers, libraries for other languages, games with tight frame budgets.

If you’re writing a web backend, Go is the more comfortable choice today. If you need full control, Zig is closer to what you want. See Zig for Go Developers.

Zig C Rust Go
Memory Manual, through allocators you pass in Manual, malloc/free Ownership, checked at compile time Garbage collected
Memory safety Runtime checks in debug/safe builds; no use-after-free guarantee Mostly up to you Guaranteed at compile time outside unsafe Guaranteed by the GC and bounds checks
Errors Error unions, try, must be handled Return codes, errno Result, ? error values, if err != nil
Generic code comptime Macros, void * Generics and traits Type parameters
Running things at once Threads, std.Io async Threads (pthreads etc.) Threads, async with a runtime library Goroutines and channels
Build tool zig build (built in) make, CMake and many others Cargo (built in) go build (built in)
Packages URLs in build.zig.zon, no central registry No standard way crates.io Go modules
Calling C Direct, and it compiles C too It is C FFI, bindgen cgo
Stable 1.0? No, still 0.x Yes (ISO standard) Yes, since 2015 Yes, since 2012

A note on speed: Zig, C and Rust all compile to native code through LLVM (or, for Zig, its own backends too) and can be equally fast when the code is written with the same care. Go is also compiled to native code, with a GC on top. Benchmarks depend so much on the program and the effort put in that we don’t quote any here.

  • Pick C when the platform only has a C compiler, when you’re joining a C codebase, or when you need a standard that won’t change under you.
  • Pick Rust when memory safety must be proven, for example in security-sensitive code, when many people work on the same code, or when you want a large set of stable libraries today.
  • Pick Go for network services, command-line tools and cloud software where a GC is fine and a fast team matters more than the last bit of control.
  • Pick Zig when you want C-level control with better tools, when you work with C code a lot, when you need easy cross-compiling, or when you like a small language you can keep in your head.

You should know these before you start:

  • It’s not 1.0. Every release breaks some code. 0.16 changed how programs print, read files and get arguments; 0.17 removed @cImport and more. Plenty of tutorials and answers online no longer compile. This site targets 0.17.1, and the 0.17.0 release notes list what changed.
  • Fewer libraries. The ecosystem is young. You’ll often call a C library, or write the thing yourself.
  • Documentation has gaps. The language reference is good, but parts of the standard library are best learned by reading its source.
  • Memory bugs are still possible. The checks catch many of them while you develop, but not all. That’s the trade you make for not having a borrow checker or a GC.

None of these stopped real projects like Ghostty and TigerBeetle from being built in Zig (see Zig in the Real World). They’re the price of using a language while it’s still being shaped.

Change the Zig sum so it skips empty strings instead of failing on them. Test it with "10", "" and "32".

Hint: check text.len == 0 at the top of the loop and continue.

Show solution
const std = @import("std");
fn sum(texts: []const []const u8) !i64 {
var total: i64 = 0;
for (texts) |text| {
if (text.len == 0) continue;
total += try std.fmt.parseInt(i64, text, 10);
}
return total;
}
pub fn main() void {
if (sum(&.{ "10", "", "32" })) |total| {
std.debug.print("sum: {d}\n", .{total});
} else |err| {
std.debug.print("error: {t}\n", .{err});
}
}

Output:

sum: 42

Without the check, parseInt fails on "" with error.InvalidCharacter. continue jumps to the next item, the same as in C, Rust and Go.

Write a main that sums "7", "x", "5" but treats any bad number as 0 instead of failing, so it prints sum: 12.

Hint: catch 0 replaces an error with a value: std.fmt.parseInt(i64, text, 10) catch 0.

Show solution
const std = @import("std");
pub fn main() void {
const texts = [_][]const u8{ "7", "x", "5" };
var total: i64 = 0;
for (texts) |text| {
total += std.fmt.parseInt(i64, text, 10) catch 0;
}
std.debug.print("sum: {d}\n", .{total});
}

Output:

sum: 12

try passes the error up; catch handles it on the spot. Since nothing can fail any more, main returns plain void. Python does the same with try/except around each number, Go with an if err != nil that sets 0.

  • Zig aims at C’s jobs with better tools: slices, error unions, comptime, safety checks and a built-in build system.
  • No hidden control flow: no exceptions, no destructors, no operator overloading.
  • Rust proves memory safety at compile time; Zig checks at runtime in debug/safe builds and keeps the language small.
  • Go has a GC and goroutines; Zig has allocators and no runtime, so it fits lower-level work.
  • Zig is pre-1.0: expect breaking changes and a young ecosystem.

Next up: Zig for C Developers, the C ideas you know and what Zig uses instead.

Quick check

1. How does Zig keep memory safe compared to Rust?
2. What does "no hidden control flow" mean in Zig?
3. Which of these is a real downside of Zig today?