When a service must stay reliable without wasting resources, Zig gives its programmer direct control rather than hiding the machinery. Zig is a systems programming language oriented toward simple, maintainable, performant software with minimal dependencies. Its approach favors understanding and careful planning over the fastest possible prototype. section 1.0 section 1.7.3
Zig works alongside C and C++ rather than trying to replace them. C ABI compatibility helps Zig libraries expose interfaces to existing software, while the build system supports cross-compilation and multi-language projects. Its bundled formatter enforces one code style, and its build tooling supports hermetic builds and reproducible package management. section 1.2 section 1.7.1 section 1.2.3 section 1.8
Zig makes several responsibilities explicit:
- Handle errors and return values, or explicitly discard them. The compiler checks that these decisions are not silently skipped. section 1.3.1
- Use const for a variable that is not reassigned; declaring an unchanged variable as var is an error. Unused variables and parameters must also be explicitly discarded. section 1.3.1
- Choose how memory is managed and how long data lives. Manual management offers control and configurability, but demands planning that garbage collection can avoid. section 1.3.3
- Treat undefined behavior deliberately. Zig includes safety checks and pointer types that help make unsafe memory operations harder to invoke accidentally. section 1.2.3
The type system supplies numeric and logical types, pointers, arrays, and slices. Strings are bytes in memory with an encoding; structs group values of potentially different types. The special types type and comptime_int support comptime features, while interfaces underpin standard-library facilities such as readers, writers, and allocators. section 2.4 section 1.8
Picking a type for 42
The integer 42 can fit in either i32 or u8. The first is a signed 32-bit integer; the second is an unsigned 8-bit integer. Zig also supports integer types with other bit widths, so the choice can reflect the data being represented. section 2.1.2
Table 2.1 Basic Zig types
| Name | Explanation |
|
Logical type. |
|
Signed (two’s-complement) integer type. In practice, you will mostly use |
|
Unsigned integer type. In practice, you will mostly use |
|
Special unsigned and signed integer types intended for usage as indices or offsets. These are equivalent to Rust’s |
|
Standard floating point types. |
|
You can think of this as a type that represents nothing, nada, zilch. More formally, there is only one possible value of |
|
Types in Zig are actually values, too! More specifically, type annotations in Zig are expressions like any other expression. With |
|
Special types, mainly for integer and float constants, that can’t exist at runtime. These are arbitrarily precise, so that they can coerce to any integer or float type that can hold them. For now, you can treat this as a curiosity. |
Compare Zig’s basic logical, integer, floating-point, and other types. section 2.1.2
Zig fits system libraries, firmware, operating systems, servers, plugins, WebAssembly, and performance-sensitive applications. It can integrate with application frameworks that expose a C interface, but may be overkill for an unoptimized GUI or a quick prototype. Its strictness can frustrate newcomers: read compiler errors closely, and expect to take responsibility for behavior that other languages might hide. section 1.7.1 section 1.7.2 section 1.7.5 section 1.7.6
