Primitive Types

5.1 Integer Types

i8, i16, i32, i64, i128 u8, u16, u32, u64, u128 isize, usize

Pointer-sized (indices and lengths use usize) iN / uN (any N from 0 to 65535)

Arbitrary bit-width: u3, i7, u48, u1...

c_int, c_uint, c_long, c_char, c_short, ...

Arbitrary-precision compile-time integer (type of literals)

5.2 Floats

f16, f32, f64, f80, f128 C long double Compile-time float (f128 precision)

5.3 Other Primitive Types

true / false Zero-size type ({} is the void value) Type of expressions that never return (return, break, unreachable, @panic, infinite loops)

Type-erased pointee (like C's void), used as *anyopaque The type of types (comptime only) The global error set comptime_int, comptime_float Literals' types @TypeOf(null), @TypeOf(undefined) Special literal types

5.4 Literals

const dec = 1_000_000;
const hex = 0xFF;
const oct = 0o755;
const bin = 0b1010_1010;
const f = 1.5e3;
const hex_float = 0x1.8p1;
const ch = 'A';                // u8 value 65 (character literals are comptime_int code points)
const uni = '💯';              // code point as comptime_int
const s = "string";            // *const [6:0]u8
const multi =
    \\Multiline string
    \\  keeps spaces
    \\no escapes needed \n
;
const inf = std.math.inf(f64);
const nan = std.math.nan(f64);

5.5 Type Limits

std.debug.print("{d} {d}\n", .{ std.math.maxInt(u8), std.math.minInt(i8) });   // 255 -128
std.debug.print("{d}\n", .{ @sizeOf(u48) });                                     // 8 (ABI size)
std.debug.print("{d}\n", .{ @bitSizeOf(u48) });                                  // 48