Zig
The Zig programming language.
Learn
Notes
- Builtin functions are prefixed with
@. pubis 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/orinstead of&&/||.if/elsecan be used as a ternary operator.switchis exhaustive: missing cases is a compile-time error.- Any value can be declared as optional by prepending the type with
?. Optional types can benull. undefinedis used for uninitialized variables.deferexecutes on scope exit,errdeferexecutes 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.