liveBook · Manning

Standard library

As explained in Systems Programming with Zig

A standard library is the collection of general-purpose modules and APIs distributed as part of a programming language implementation.

Need to print a value, allocate memory, parse command-line arguments, or use a file? Zig’s standard library, std, supplies tools for these jobs. It is optional: you can replace its functionality with your own code, but its data structures and APIs are designed to be flexible and customizable. section 2.1 section 3.1

Import the std module with the compiler builtin @import and assign it to a constant. Dot syntax then reaches declarations inside its namespaces: std.debug.print names the print function in std.debug. section 2.1

Listing 2.1 A simple program
const std = @import("std"); #1

pub fn main() void { #2
    const x: i32 = 42; #3
    std.debug.print("{}\n", .{x}); #4
}

A minimal program imports std and uses std.debug.print to print an integer. section 2.1

The library also provides allocators and std.Io, which shape how Zig programs handle memory and I/O. For a larger project, standard-library networking can help turn a command-line word ladder game into a web application. section 3.1 section 4.2

Keep the standard-library documentation handy: run zig std to open it locally when network access is spotty. section 3.1

How Systems Programming with Zig covers it

How deep it goes
Explains importing and accessing std declarations, introduces major uses, and defers comprehensive coverage to the documentation.
Examples
Uses integer printing and a word ladder game adapted into a web application.
What you can do after
Apply it via Zig’s std module to access library declarations and print a value.
How it connects
Connects std with allocators, I/O, TCP, and HTTP.

Also explained in

Compare how 8 books explain standard library →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Systems Programming with Zig. The section links point to the parts of the book it draws on.