test "linked list" { // Functions called at compile-time are memoized. This means you can // do this: tryexpect(LinkedList(i32) == LinkedList(i32));
var list = LinkedList(i32) { .first = null, .last = null, .len = 0, }; tryexpect(list.len == 0);
// Since types are first class values you can instantiate the type // by assigning it to a variable: const ListOfInts = LinkedList(i32); tryexpect(ListOfInts == LinkedList(i32)); }
// Coerce from child type of an optional foo = 1234;
// Use compile-time reflection to access the child type of the optional: comptime tryexpect(@typeInfo(@TypeOf(foo)).Optional.child == i32);
// Pointers cannot be null. If you want a null pointer, use the optional // prefix `?` to make the pointer type optional. var ptr: ?*i32 = null;
var x: i32 = 1; ptr = &x;
tryexpect(ptr.?.* == 1);
// Optional pointers are the same size as normal pointers, because pointer // value 0 is used as the null value. tryexpect(@sizeOf(?*i32) == @sizeOf(*i32));
build Build project from build.zig init-exe Initialize a `zig build` application in the cwd init-lib Initialize a `zig build` library in the cwd
ast-check Look for simple compile errors in any set of files build-exe Create executable from source or object files build-lib Create library from source or object files build-obj Create object from source or object files fmt Reformat Zig source into canonical form run Create executable and run immediately test Create and run a test build translate-c Convert C code to Zig code
ar Use Zig as a drop-in archiver cc Use Zig as a drop-in C compiler c++ Use Zig as a drop-in C++ compiler dlltool Use Zig as a drop-in dlltool.exe lib Use Zig as a drop-in lib.exe ranlib Use Zig as a drop-in ranlib objcopy Use Zig as a drop-in objcopy
env Print lib path, std path, cache directory, and version help Print this help and exit libc Display native libc paths file or validate one targets List available compilation targets version Print version number and exit zen Print Zen of Zig and exit