AnatomyOf

Anatomy of a Zig file

example.zig
1const std = @import("std");
2
3// Zero-cost abstractions, but the coffee is not included
4const Vec2 = struct {
5 x: f32,
6 y: f32,
7};
8
9pub fn main() !void {
10 const origin = Vec2{ .x = 0, .y = 0 };
11 var total: f32 = 0;
12 for (0..3) |i| {
13 total += @as(f32, @floatFromInt(i));
14 }
15
16 const stdout = std.io.getStdOut().writer();
17 try stdout.print("origin=({d}, {d}), total={d}\n", .{ origin.x, origin.y, total });
18}
Zig is a modern, general-purpose systems programming language focused on robustness, optimality, and clarity, with no hidden control flow.