Targets · Zig · Reserved words
Reserved words
Zig keeps a set of words for its own syntax, so a program cannot use them as names. When a Program
name collides with one, the renderer appends a single underscore — fn becomes
fn_ — so the program keeps the name it chose and the output still compiles. Because
_ is illegal in a Program identifier, the escape can never collide with a name a program
actually chose.
Contents
How a Program becomes Zig, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.
- Introduction — what the Zig target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the Zig it renders to.
- Naming considerations — how Program's dotted names are carried into Zig.
- Entry point — starting a program from
mainwith its drivers. - Drivers — the native drivers that provide the interface, console and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written Zig behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to Zig.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words Zig keeps for itself, and how a colliding name is escaped.
The full list
Every word Zig reserves, with the identifier a colliding Program name is escaped to. The rule is
uniform — append a single _:
| Reserved word | Rendered identifier |
|---|---|
addrspace | addrspace_ |
align | align_ |
allowzero | allowzero_ |
and | and_ |
anyframe | anyframe_ |
anytype | anytype_ |
asm | asm_ |
async | async_ |
await | await_ |
break | break_ |
callconv | callconv_ |
catch | catch_ |
comptime | comptime_ |
const | const_ |
continue | continue_ |
defer | defer_ |
else | else_ |
enum | enum_ |
errdefer | errdefer_ |
error | error_ |
export | export_ |
extern | extern_ |
fn | fn_ |
for | for_ |
if | if_ |
inline | inline_ |
noalias | noalias_ |
noinline | noinline_ |
nosuspend | nosuspend_ |
opaque | opaque_ |
or | or_ |
orelse | orelse_ |
packed | packed_ |
pub | pub_ |
resume | resume_ |
return | return_ |
linksection | linksection_ |
struct | struct_ |
suspend | suspend_ |
switch | switch_ |
test | test_ |
threadlocal | threadlocal_ |
try | try_ |
union | union_ |
unreachable | unreachable_ |
usingnamespace | usingnamespace_ |
var | var_ |
volatile | volatile_ |
while | while_ |