⚡ Zig Guide LiveUnofficialbut fully verified
✓ Zig 0.17.0-dev.1516+8a4b5424dWhat's newOn an older Zig?

Survive the Terminal

Before a shell can run a command it has to measure a string, compare one, copy one without running off the end, split a line into arguments, and loop until the user or the input stops. Three chapters, each one primitive built rather than imported. The parts that need a real kernel, fork, exec and pipes, are in the operating system section already.

  1. strlen is a walk, every time you call it. That cost is the whole argument for a slice that already knows its length.
  2. A buffer for a 5-byte string needs 6 bytes. The version of the bounds check that forgets the terminator passes a casual test and writes one byte past the end.
  3. Trimming returns a view, not a copy. Moving bytes to remove spaces is work you never needed to do.
  4. A REPL has two exits, not one. A loop that only watches for quit spins forever the first time someone presses Ctrl-D.

3 chapters.