Keyword Reference

KeywordDescription
  1. addrspace
The addrspace keyword.
  • TODO add documentation for addrspace
  1. align
align can be used to specify the alignment of a pointer. It can also be used after a variable or function declaration to specify the alignment of pointers to that variable or function.
  1. allowzero
The pointer attribute allowzero allows a pointer to have address zero.
  1. and
The boolean operator and.
  1. anyframe
anyframe can be used as a type for variables which hold pointers to function frames.
  1. anytype
Function parameters can be declared with anytype in place of the type. The type will be inferred where the function is called.
  1. asm
asm begins an inline assembly expression. This allows for directly controlling the machine code generated on compilation.
  1. async
async can be used before a function call to get a pointer to the function’s frame when it suspends.
  1. await
await can be used to suspend the current function until the frame provided after the await completes. await copies the value returned from the target function’s frame to the caller.
  1. break
break can be used with a block label to return a value from the block. It can also be used to exit a loop before iteration completes naturally.
  1. callconv
callconv can be used to specify the calling convention in a function type.
  1. catch
catch can be used to evaluate an expression if the expression before it evaluates to an error. The expression after the catch can optionally capture the error value.
  1. comptime
comptime before a declaration can be used to label variables or function parameters as known at compile time. It can also be used to guarantee an expression is run at compile time.
  1. const
const declares a variable that can not be modified. Used as a pointer attribute, it denotes the value referenced by the pointer cannot be modified.
  1. continue
continue can be used in a loop to jump back to the beginning of the loop.
  1. defer
defer will execute an expression when control flow leaves the current block.
  1. else
else can be used to provide an alternate branch for if, switch, while, and for expressions.
  • If used after an if expression, the else branch will be executed if the test value returns false, null, or an error.
  • If used within a switch expression, the else branch will be executed if the test value matches no other cases.
  • If used after a loop expression, the else branch will be executed if the loop finishes without breaking.
  • See also if, switch, while, for
  1. enum
enum defines an enum type.
  1. errdefer
errdefer will execute an expression when control flow leaves the current block if the function returns an error, the errdefer expression can capture the unwrapped value.
  1. error
error defines an error type.
  1. export
export makes a function or variable externally visible in the generated object file. Exported functions default to the C calling convention.
  1. extern
extern can be used to declare a function or variable that will be resolved at link time, when linking statically or at runtime, when linking dynamically.
  1. fn
fn declares a function.
  1. for
A for expression can be used to iterate over the elements of a slice, array, or tuple.
  1. if
An if expression can test boolean expressions, optional values, or error unions. For optional values or error unions, the if expression can capture the unwrapped value.
  • See also if
  1. inline
inline can be used to label a loop expression such that it will be unrolled at compile time. It can also be used to force a function to be inlined at all call sites.
  1. linksection
The linksection keyword can be used to specify what section the function or global variable will be put into (e.g. .text).
  1. noalias
The noalias keyword.
  • TODO add documentation for noalias
  1. noinline
noinline disallows function to be inlined in all call sites.
  1. nosuspend
The nosuspend keyword can be used in front of a block, statement or expression, to mark a scope where no suspension points are reached. In particular, inside a nosuspend scope:
  • Using the suspend keyword results in a compile error.
  • Using await on a function frame which hasn’t completed yet results in safety-checked Undefined Behavior.
  • Calling an async function may result in safety-checked Undefined Behavior, because it’s equivalent to await async some_async_fn(), which contains an await.
Code inside a nosuspend scope does not cause the enclosing function to become an async function.
  1. opaque
opaque defines an opaque type.
  1. or
The boolean operator or.
  1. orelse
orelse can be used to evaluate an expression if the expression before it evaluates to null.
  1. packed
The packed keyword before a struct definition changes the struct’s in-memory layout to the guaranteed packed layout.
  1. pub
The pub in front of a top level declaration makes the declaration available to reference from a different file than the one it is declared in.
  1. resume
resume will continue execution of a function frame after the point the function was suspended.
  1. return
return exits a function with a value.
  1. struct
struct defines a struct.
  1. suspend
suspend will cause control flow to return to the call site or resumer of the function. suspend can also be used before a block within a function, to allow the function access to its frame before control flow returns to the call site.
  1. switch
A switch expression can be used to test values of a common type. switch cases can capture field values of a Tagged union.
  1. test
The test keyword can be used to denote a top-level block of code used to make sure behavior meets expectations.
  1. threadlocal
threadlocal can be used to specify a variable as thread-local.
  1. try
try evaluates an error union expression. If it is an error, it returns from the current function with the same error. Otherwise, the expression results in the unwrapped value.
  1. union
union defines a union.
  1. unreachable
unreachable can be used to assert that control flow will never happen upon a particular location. Depending on the build mode, unreachable may emit a panic.
  • Emits a panic in Debug and ReleaseSafe mode, or when using zig test.
  • Does not emit a panic in ReleaseFast and ReleaseSmall mode.
  • See also unreachable
  1. usingnamespace
usingnamespace is a top-level declaration that imports all the public declarations of the operand, which must be a struct, union, or enum, into the current scope.
  1. var
var declares a variable that may be modified.
  1. volatile
volatile can be used to denote loads or stores of a pointer have side effects. It can also modify an inline assembly expression to denote it has side effects.
  1. while
A while expression can be used to repeatedly test a boolean, optional, or error union expression, and cease looping when that expression evaluates to false, null, or an error, respectively.