#
Keyword Reference
| Keyword | Description |
|---|---|
<br>addrspace<br> |
The addrspace keyword.- TODO add documentation for addrspace |
<br>align<br> |
align can be usedto 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. - See also Alignment |
<br>allowzero<br> |
The pointer attribute allowzero allows a pointer to have address zero.- See also allowzero |
<br>and<br> |
The boolean operator and.- See also Operators |
<br>anyframe<br> |
anyframe can be used as a type for variables which hold pointers to function frames.- See also Async Functions |
<br>anytype<br> |
Function parameters can be declared with anytype in place of the type.The type will be inferred where the function is called. - See also Function Parameter Type Inference |
<br>asm<br> |
asm begins an inline assembly expression. This allows for directly controlling the machine code generated on compilation.- See also Assembly |
<br>break<br> |
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. - See also Blocks, while, for |
<br>callconv<br> |
callconv can be used to specify the calling convention in a function type.- See also Functions |
<br>catch<br> |
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.- See also catch, Operators |
<br>comptime<br> |
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. - See also comptime |
<br>const<br> |
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. - See also Variables |
<br>continue<br> |
continue can be used in a loop to jump back to the beginning of the loop.- See also while, for |
<br>defer<br> |
defer will execute an expression when control flow leaves the current block.- See also defer |
<br>else<br> |
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 |
<br>enum<br> |
enum defines an enum type.- See also enum |
<br>errdefer<br> |
errdefer willexecute an expression when control flow leaves the current block if the function returns an error, the errdefer expression can capture the unwrapped value. - See also errdefer |
<br>error<br> |
error defines an error type.- See also Errors |
<br>export<br> |
export makes a function or variable externally visible in the generated object file.Exported functions default to the C calling convention. - See also Functions |
<br>extern<br> |
extern can be used to declare a function or variable that will be resolved at link time, when linking staticallyor at runtime, when linking dynamically. - See also Functions |
<br>fn<br> |
fn declares a function.- See also Functions |
<br>for<br> |
A for expression can be used to iterate over the elements of a slice, array, or tuple.- See also for |
<br>if<br> |
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 |
<br>inline<br> |
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. - See also inline while, inline for, Functions |
<br>linksection<br> |
The linksection keyword can be used to specify what section the function or global variable will be put into (e.g. .text). |
<br>noalias<br> |
The noalias keyword.- TODO add documentation for noalias |
<br>noinline<br> |
noinline disallows function to be inlined in all call sites.- See also Functions |
<br>nosuspend<br> |
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 Illegal Behavior.- Calling an async function may result in safety-checked Illegal 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.- See also Async Functions |
<br>opaque<br> |
opaque defines an opaque type.- See also opaque |
<br>or<br> |
The boolean operator or.- See also Operators |
<br>orelse<br> |
orelse can be used to evaluate an expression if the expression before it evaluates to null.- See also Optionals, Operators |
<br>packed<br> |
The packed keyword before a struct definition changes the struct's in-memory layoutto the guaranteed packed layout.- See also packed struct |
<br>pub<br> |
The pub in front of a top level declaration makes the declaration availableto reference from a different file than the one it is declared in. - See also import |
<br>resume<br> |
resume will continue execution of a function frame after the point the function was suspended. |
<br>return<br> |
return exits a function with a value.- See also Functions |
<br>struct<br> |
struct defines a struct.- See also struct |
<br>suspend<br> |
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. |
<br>switch<br> |
A switch expression can be used to test values of a common type.switch cases can capture field values of a Tagged union.- See also switch |
<br>test<br> |
The test keyword can be used to denote a top-level block of codeused to make sure behavior meets expectations. - See also Zig Test |
<br>threadlocal<br> |
threadlocal can be used to specify a variable as thread-local.- See also Thread Local Variables |
<br>try<br> |
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. - See also try |
<br>union<br> |
union defines a union.- See also union |
<br>unreachable<br> |
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 |
<br>var<br> |
var declares a variable that may be modified.- See also Variables |
<br>volatile<br> |
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. - See also volatile, Assembly |
<br>while<br> |
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. - See also while |