Zig
The Zig programming language.
Learn
Notes
- Builtin functions are prefixed with
@
. pub
is used to make a function available outside the file.//
normal comments,///
doc comments.- All function parameters are constant.
- Struct fields can be given default values.
- Arrays are fixed size, size of a part of the type.
- Slices are pointers to arrays with length (but without capacity).
- Strings are pointers to arrays of
u8
. - String literals are NULL-terminated, like in C.
.{}
creates an anonymous struct literal. This is used instead of variadic parameters.and
/or
instead of&&
/||
.if
/else
can be used as a ternary operator.switch
is exhaustive: missing cases is a compile-time error.- Any value can be declared as optional by prepending the type with
?
. Optional types can benull
. undefined
is used for uninitialized variables.defer
executes on scope exit,errdefer
executes on error.foo.*
: pointer dereference.- There are no interfaces, but interface-like things such as
std.mem.Allocator
. - Types are first-class citizens.
- Generics are implemented using
comptime
.