Skip to content

No return

Chung Leong edited this page Jun 2, 2024 · 4 revisions

noreturn is not a real type in Zig, as it's logically impossible to create an actual instance. It is used to indicate that a function never returns. std.process.exit() for example:

const std = @import("std");

pub const exit = std.process.exit;
import { exit } from './noreturn-example-1.zig';

exit(0);

When the above code is used in Node.js, calling quit() would terminate the program. When it's used in the browser, nothing happens if the exit code is zero. An error is thrown if the exit code is not zero.

Clone this wiki locally