// Are all of these pointer types starting to get confusing? // // FREE ZIG POINTER CHEATSHEET! (Using u8 as the example type.) // +---------------+----------------------------------------------+ // | u8 | one u8 | // | *u8 | pointer to one u8 | // | [2]u8 | two u8s | // | [*]u8 | pointer to unknown number of u8s | // | [*]const u8 | pointer to unknown number of immutable u8s | // | *[2]u8 | pointer to an array of 2 u8s | // | *const [2]u8 | pointer to an immutable array of 2 u8s | // | []u8 | slice of u8s | // | []const u8 | slice of immutable u8s | // +---------------+----------------------------------------------+ const zen12: *const [21]u8 = "Memory is a resource."; const zen_manyptr: [*]const u8 = zen12; const zen12_string: []const u8 = zen_manyptr[0..21]; u8 single item // *u8 single-item pointer // []u8 slice (size known at runtime) // [5]u8 array of 5 u8s // [*]u8 many-item pointer (zero or more) // enum {a, b} set of unique values a and b // error {e, f} set of unique error values e and f // struct {y: u8, z: i32} group of values y and z // union(enum) {a: u8, b: i32} single value either u8 or i32 // var a: E!u8 = 5; // can be u8 or error from set E // var b: ?u8 = 5; // can be u8 or null