What Zig Does
- No hidden control flow — no operator overloading, no exceptions, no implicit allocations
- Manual memory with allocators — all allocation is explicit; pass allocators as parameters
- Comptime — compile-time evaluation for generics, type reflection, code gen
- Error union types —
!Treturn types replace exceptions - C ABI interop — call C directly, compile C with
zig cc - Cross-compile — any target from any host, no extra toolchain
- Build system —
zig buildreplaces make/cmake - Safety modes — Debug, ReleaseSafe, ReleaseFast, ReleaseSmall
- Async/await — cooperative multitasking (frozen in recent versions)
Architecture
Compiler built on top of LLVM (Zig also has a self-hosted backend in progress). Comptime is the star feature — Zig runs normal Zig code at compile time for generics, type transformation, and code generation. Zig cc uses Clang and bundled libc headers for turnkey C/C++ cross-compilation.
Self-Hosting
Language toolchain.
Key Features
- Simpler than C++, safer than C
- Explicit memory allocators
- Comptime metaprogramming
- Error union types
- Cross-compile everywhere
- Zig as a C/C++ compiler
- Build system built in
- Great stack traces in Debug mode
- WebAssembly target
- Bit-packed structs
Comparison
| Language | Memory Model | Cross-Compile | Comptime |
|---|---|---|---|
| Zig | Manual + allocators | Trivial | First-class |
| Rust | Ownership | Harder | Limited (macros) |
| C | Manual | Hard | Preprocessor |
| C++ | Manual + RAII | Hard | Templates |
| Go | GC | Good | Limited |
| Odin | Manual | Good | Limited |
常见问题 FAQ
Q: Zig vs Rust? A: Rust 追求编译时内存安全(borrow checker);Zig 追求简单性和可读性,保留手动内存管理但加上工具(GPA 内存检测)。Zig 更容易学,Rust 更安全。
Q: 已经稳定了吗? A: 还没到 1.0。v0.13+ 稳定性快速提升。生产项目如 Bun、TigerBeetle 在用。
Q: 为什么能当 C 编译器?
A: Zig 打包了 LLVM + Clang + 完整 libc 头文件集合,所以 zig cc 可以 cross-compile C/C++ 到任何 LLVM 支持的 target,零配置。
来源与致谢 Sources
- Docs: https://ziglang.org/documentation
- GitHub: https://github.com/ziglang/zig
- License: MIT