package base:builtin

⌘K
Ctrl+K
or
/

    Overview

    package builtin provides documentation for Odin's predeclared identifiers. The items documented here are not actually in package builtin but here to allow for better documentation for the language's special identifiers.

    Index

    Procedures (107)

    Constants

    ODIN_ARCH ¶

    ODIN_ARCH : runtime.Odin_Arch_Type : …
     

    An enum value specifying the target platform's architecture.

    Example:
    // Defined internally by the compiler
    Odin_Arch_Type :: enum int {
    	Unknown,
    	amd64,
    	i386,
    	arm32,
    	arm64,
    	wasm32,
    	wasm64p32,
    	riscv64,
    }
    

    ODIN_BUILD_MODE ¶

    ODIN_BUILD_MODE : runtime.Odin_Build_Mode_Type : …
     

    An enum value specifying the "build-mode".

    Example:
    // Defined internally by the compiler
    Odin_Build_Mode_Type :: enum int {
    	Executable,
    	Dynamic,
    	Static,
    	Object,
    	Assembly,
    	LLVM_IR,
    }
    

    ODIN_COMPILE_TIMESTAMP ¶

    ODIN_COMPILE_TIMESTAMP :: … // untyped integer
     

    Equal to the UNIX timestamp in nanoseconds at the time of the program's compilation.

    ODIN_DEBUG ¶

    ODIN_DEBUG :: … // untyped boolean
     

    Equal to true if the -debug flag has been set during compilation, otherwise false.

    ODIN_DEFAULT_TO_NIL_ALLOCATOR ¶

    ODIN_DEFAULT_TO_NIL_ALLOCATOR :: … // untyped boolean
     

    Equal to true if the -default-to-nil-allocator flag has been set during compilation or whether the current target defaults to the "nil allocator", otherwise false.

    ODIN_DEFAULT_TO_PANIC_ALLOCATOR ¶

    ODIN_DEFAULT_TO_PANIC_ALLOCATOR :: … // untyped boolean
     

    Equal to true if the -default-to-panic-allocator flag has been set during compilation or whether the current target defaults to the "panic allocator", otherwise false.

    ODIN_DISABLE_ASSERT ¶

    ODIN_DISABLE_ASSERT :: … // untyped boolean
     

    Equal to true if the -disable-assert flag has been set during compilation, otherwise false.

    ODIN_ENDIAN ¶

    ODIN_ENDIAN : runtime.Odin_Endian_Type : …
     

    An enum value specifying the target platform's endiannes.

    Example:
    // Defined internally by the compiler
    Odin_Endian_Type :: enum int {
    	Unknown,
    	Little,
    	Big,
    }
    

    ODIN_ERROR_POS_STYLE ¶

    ODIN_ERROR_POS_STYLE : runtime.Odin_Error_Pos_Style_Type : …
     

    An enum value specifying whether errors should be stylized in the default (MSVC-like) style or a UNIX (GCC-like) style.

    Default = `path(1:2) Unix = `path:1:2:

    ODIN_NO_CRT ¶

    ODIN_NO_CRT :: … // untyped boolean
     

    Equal to true if the -no-crt flag has been set during compilation (disallowing the C Run-Time library), otherwise false.

    ODIN_NO_ENTRY_POINT ¶

    ODIN_NO_ENTRY_POINT :: … // untyped boolean
     

    Equal to true if the -no-entry-point flag has been set during compilation, otherwise false.

    ODIN_NO_RTTI ¶

    ODIN_NO_RTTI :: … // untyped boolean
     

    Equal to true if the -no-rtti flag has been set during compilation (disabling Odin's Run-Time Type Information, only allowed on freestanding targets), otherwise false.

    ODIN_OS ¶

    ODIN_OS : runtime.Odin_OS_Type : …
     

    An enum value specifying the target platform's operating system.

    Example:
    // Defined internally by the compiler
    Odin_OS_Type :: enum int {
    	Unknown,
    	Windows,
    	Darwin,
    	Linux,
    	Essence,
    	FreeBSD,
    	OpenBSD,
    	NetBSD,
    	Haiku,
    	WASI,
    	JS,
    	Orca,
    	Freestanding,
    }
    

    ODIN_PLATFORM_SUBTARGET ¶

    ODIN_PLATFORM_SUBTARGET : runtime.Odin_Platform_Subtarget_Type : …
     

    An enum value specifying the selected subtarget type, only useful for Darwin targets.

    Example:
    // Defined internally by the compiler
    Odin_Platform_Subtarget_Type :: enum int {
    	Default,
    	iPhone,
    	iPhoneSimulator
    	Android,
    }
    

    ODIN_ROOT ¶

    ODIN_ROOT :: … // untyped string
     

    The path to the root Odin directory.

    ODIN_VENDOR ¶

    ODIN_VENDOR :: … // untyped string
     

    A string specifying the current Odin compiler vendor.

    ODIN_VERSION ¶

    ODIN_VERSION :: … // untyped string
     

    A string specifying the current Odin version.

    ODIN_WINDOWS_SUBSYSTEM ¶

    ODIN_WINDOWS_SUBSYSTEM :: … // untyped string
     

    A string specifying the current Windows subsystem, only useful on Windows targets.

    false ¶

    false :: 0 != 0 // untyped boolean
     

    nil ¶

    nil :: … // untyped nil
     

    nil is a predeclared identifier representing the zero value for a pointer, multi-pointer, enum, bit_set, slice, dynamic array, map, procedure, any, typeid, cstring, union, #soa array, #soa pointer, #relative type

    true ¶

    true :: 0 == 0 // untyped boolean
     

    ODIN_PLATFORM_SUBTARGET_IOS ¶

    ODIN_PLATFORM_SUBTARGET_IOS: bool : ODIN_PLATFORM_SUBTARGET == .iPhone || ODIN_PLATFORM_SUBTARGET == .iPhoneSimulator

    Types

    any ¶

    any :: any
     

    any can reference any data type at runtime. Internally it contains a pointer to the underlying data and its relevant typeid. This is a very useful construct in order to have a runtime type safe printing procedure.

    Note: The any value is only valid for as long as the underlying data is still valid. Passing a literal to an any will allocate the literal in the current stack frame.

    Note: It is highly recommend that you do not use this unless you know what you are doing. Its primary use is for printing procedures.

    b16 ¶

    b16 :: b16
     

    b16 is the set of boolean values, false and true. b16 has a size of 2 bytes (16 bits).

    b32 ¶

    b32 :: b32
     

    b32 is the set of boolean values, false and true. b32 has a size of 4 bytes (32 bits).

    b64 ¶

    b64 :: b64
     

    b64 is the set of boolean values, false and true. b64 has a size of 8 bytes (64 bits).

    b8 ¶

    b8 :: b8
     

    b8 is the set of boolean values, false and true. This is distinct to bool. b8 has a size of 1 byte (8 bits).

    bool ¶

    bool :: bool
     

    bool is the set of boolean values, false and true. This is distinct to b8. bool has a size of 1 byte (8 bits).

    byte ¶

    byte :: u8
     

    byte is an alias for u8 and is equivalent to u8 in all ways. It is used as a convention to distinguish values from 8-bit unsigned integer values.

    complex128 ¶

    complex128 :: complex128
     

    complex128 is the set of all complex numbers with f64 real and imaginary parts

    complex32 ¶

    complex32 :: complex32
     

    complex32 is the set of all complex numbers with f16 real and imaginary parts

    complex64 ¶

    complex64 :: complex64
     

    complex64 is the set of all complex numbers with f32 real and imaginary parts

    cstring ¶

    cstring :: cstring
     

    cstring is the set of all strings of 8-bit bytes terminated with a NUL (0) byte, conventionally but not necessarily representing UTF-8 encoding text. A cstring may be empty or nil. Elements of string type are immutable but not indexable.

    f16 ¶

    f16 :: f16
     

    f16 is the set of all IEEE-754 16-bit floating-point numbers with native endianness.

    f16be ¶

    f16be :: f16be
     

    f16be is the set of all IEEE-754 16-bit floating-point numbers with big endianness.

    f16le ¶

    f16le :: f16le
     

    f16le is the set of all IEEE-754 16-bit floating-point numbers with little endianness.

    f32 ¶

    f32 :: f32
     

    f32 is the set of all IEEE-754 32-bit floating-point numbers with native endianness.

    f32be ¶

    f32be :: f32be
     

    f32be is the set of all IEEE-754 32-bit floating-point numbers with big endianness.

    f32le ¶

    f32le :: f32le
     

    f32le is the set of all IEEE-754 32-bit floating-point numbers with little endianness.

    f64 ¶

    f64 :: f64
     

    f64 is the set of all IEEE-754 64-bit floating-point numbers with native endianness.

    f64be ¶

    f64be :: f64be
     

    f64be is the set of all IEEE-754 64-bit floating-point numbers with big endianness.

    f64le ¶

    f64le :: f64le
     

    f64le is the set of all IEEE-754 64-bit floating-point numbers with little endianness.

    i128 ¶

    i128 :: i128
     

    i128 is the set of all signed 128-bit integers with native endianness. Range -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727.

    i128be ¶

    i128be :: i128be
     

    i128be is the set of all signed 128-bit integers with big endianness. Range -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727.

    i128le ¶

    i128le :: i128le
     

    i128le is the set of all signed 128-bit integers with little endianness. Range -170141183460469231731687303715884105728 through 170141183460469231731687303715884105727.

    i16 ¶

    i16 :: i16
     

    i16 is the set of all signed 16-bit integers with native endianness. Range -32768 through 32767.

    i16be ¶

    i16be :: i16be
     

    i16be is the set of all signed 16-bit integers with big endianness. Range -32768 through 32767.

    i16le ¶

    i16le :: i16le
     

    i16le is the set of all signed 16-bit integers with little endianness. Range -32768 through 32767.

    i32 ¶

    i32 :: i32
     

    i32 is the set of all signed 32-bit integers with native endianness. Range -2147483648 through 2147483647.

    i32be ¶

    i32be :: i32be
     

    i32be is the set of all signed 32-bit integers with big endianness. Range -2147483648 through 2147483647.

    i32le ¶

    i32le :: i32le
     

    i32le is the set of all signed 32-bit integers with little endianness. Range -2147483648 through 2147483647.

    i64 ¶

    i64 :: i64
     

    i64 is the set of all signed 64-bit integers with native endianness. Range -9223372036854775808 through 9223372036854775807.

    i64be ¶

    i64be :: i64be
     

    i64be is the set of all signed 64-bit integers with big endianness. Range -9223372036854775808 through 9223372036854775807.

    i64le ¶

    i64le :: i64le
     

    i64le is the set of all signed 64-bit integers with little endianness. Range -9223372036854775808 through 9223372036854775807.

    i8 ¶

    i8 :: i8
     

    i8 is the set of all signed 8-bit integers. Range -128 through 127.

    int ¶

    int :: int
     

    int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for say, i32.

    quaternion128 ¶

    quaternion128 :: quaternion128
     

    quaternion128 is the set of all complex numbers with f32 real and imaginary (i, j, & k) parts

    quaternion256 ¶

    quaternion256 :: quaternion256
     

    quaternion256 is the set of all complex numbers with f64 real and imaginary (i, j, & k) parts

    quaternion64 ¶

    quaternion64 :: quaternion64
     

    quaternion64 is the set of all complex numbers with f16 real and imaginary (i, j, & k) parts

    rawptr ¶

    rawptr :: rawptr
     

    rawptr represents a pointer to an arbitrary type. It is equivalent to void * in C.

    rune ¶

    rune :: rune
     

    rune is the set of all Unicode code points. It is internally the same as i32 but distinct.

    string ¶

    string :: string
     

    string is the set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8 encoding text. A string may be empty but not nil. Elements of string type are immutable and indexable.

    typeid ¶

    typeid :: typeid
     

    typeid is a unique identifier for an Odin type at runtime. It can be mapped to relevant type information through type_info_of.

    u128 ¶

    u128 :: u128
     

    u128 is the set of all unsigned 128-bit integers with native endianness. Range 0 through 340282366920938463463374607431768211455.

    u128be ¶

    u128be :: u128be
     

    u128be is the set of all unsigned 128-bit integers with big endianness. Range 0 through 340282366920938463463374607431768211455.

    u128le ¶

    u128le :: u128le
     

    u128le is the set of all unsigned 128-bit integers with little endianness. Range 0 through 340282366920938463463374607431768211455.

    u16 ¶

    u16 :: u16
     

    u16 is the set of all unsigned 16-bit integers with native endianness. Range 0 through 65535.

    u16be ¶

    u16be :: u16be
     

    u16be is the set of all unsigned 16-bit integers with big endianness. Range 0 through 65535.

    u16le ¶

    u16le :: u16le
     

    u16le is the set of all unsigned 16-bit integers with little endianness. Range 0 through 65535.

    u32 ¶

    u32 :: u32
     

    u32 is the set of all unsigned 32-bit integers with native endianness. Range 0 through 4294967295.

    u32be ¶

    u32be :: u32be
     

    u32be is the set of all unsigned 32-bit integers with big endianness. Range 0 through 4294967295.

    u32le ¶

    u32le :: u32le
     

    u32le is the set of all unsigned 32-bit integers with little endianness. Range 0 through 4294967295.

    u64 ¶

    u64 :: u64
     

    u64 is the set of all unsigned 64-bit integers with native endianness. Range 0 through 18446744073709551615.

    u64be ¶

    u64be :: u64be
     

    u64be is the set of all unsigned 64-bit integers with big endianness. Range 0 through 18446744073709551615.

    u64le ¶

    u64le :: u64le
     

    u64le is the set of all unsigned 64-bit integers with little endianness. Range 0 through 18446744073709551615.

    u8 ¶

    u8 :: u8
     

    u8 is the set of all unsigned 8-bit integers. Range 0 through 255.

    uint ¶

    uint :: uint
     

    uint is an unsigned integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for say, u32.

    uintptr ¶

    uintptr :: uintptr
     

    uintptr is an unsigned integer type that is large enough to hold the bit pattern of any pointer.

    Maybe ¶

    Maybe :: union($T: typeid) {
    	… // See source for fields
    }

    Objc_Block ¶

    Objc_Block :: struct($T: typeid) {
    	… // See source for fields
    }
     

    Represents an Objective-C block with a given procedure signature T

    Procedures

    abs ¶

    abs :: proc(value: T) -> T {…}
     

    abs returns the absolute value of passed argument. If the argument is a complex or quaternion, this is equivalent to real(conj(value) * value).

    align_of ¶

    align_of :: proc($T: typeid) -> int {…}
     

    align_of takes an expression or type, and returns the alignment in bytes of the type of the expression if it was hypothetically instantiated as a variable v. It is the largest value m such that the address of v is always 0 mod m.

    cap ¶

    cap :: proc(v: Array_Type) -> int {…}
     

    The cap built-in procedure returns the length of v according to its type:

    Array: the number of elements in v.
    Pointer to (any) array: the number of elements in `v^` (even if `v` is `nil`).
    Dynamic array, or map: the reserved number of elements in `v`; if `v` is `nil`, `len(v)` is zero.
    Enum type: equal to `max(Enum)-min(Enum)+1`.
    #soa dynamic array: the reserved number of elements in `v`; if `v` is `nil`, `len(v)` is zero.
    
    

    For some arguments, such as a string literal or a simple array expression, the result can be constant.

    clamp ¶

    clamp :: proc(v, minimum, maximum: T) -> T {…}
     

    clamp returns a value v clamped between minimum and maximum. This is calculated as the following: minimum if v < minimum else maximum if v > maximum else v.

    complex ¶

    complex :: proc(real, imag: Float) -> Complex_Type {…}
     

    conj ¶

    conj :: proc(v: Complex_Or_Quaternion) -> Complex_Or_Quaternion {…}
     

    conj returns the complex conjugate of a complex or quaternion number v. This negates the imaginary component(s) whilst keeping the real component untouched.

    expand_values ¶

    expand_values :: proc(value: Struct_Or_Array) -> (A, B, C, ...) {…}
     

    expand_values will return multiple values corresponding to the multiple fields of the passed struct or the multiple elements of a passed fixed length array.

    imag ¶

    imag :: proc(v: Complex_Or_Quaternion) -> Float {…}
     

    imag returns the i-imaginary part of a complex or quaternion number v. The return value will be the floating-point type corresponding to the type of v.

    jmag ¶

    jmag :: proc(v: Quaternion) -> Float {…}
     

    jmag returns the j-imaginary part of a quaternion number v. The return value will be the floating-point type corresponding to the type of v.

    kmag ¶

    kmag :: proc(v: Quaternion) -> Float {…}
     

    kmag returns the k-imaginary part of a quaternion number v. The return value will be the floating-point type corresponding to the type of v.

    len ¶

    len :: proc(v: Array_Type) -> int {…}
     

    The len built-in procedure returns the length of v according to its type:

    Array: the number of elements in v.
    Pointer to (any) array: the number of elements in `v^` (even if `v` is `nil`).
    Slice, dynamic array, or map: the number of elements in `v`; if `v` is `nil`, `len(v)` is zero.
    String: the number of bytes in `v`
    Enumerated array: the number elements in v.`
    Enum type: the number of enumeration fields.
    #soa array: the number of elements in `v`; if `v` is `nil`, `len(v)` is zero.
    #simd vector: the number of elements in `v`.
    
    

    For some arguments, such as a string literal or a simple array expression, the result can be constant.

    max ¶

    max :: proc(values: ..T) -> T {…}
     

    max returns the maximum value of passed arguments of all the same type. If one argument is passed and it is an enum or numeric type, then max returns the maximum value of the enum type's fields or its maximum numeric value respectively.

    min ¶

    min :: proc(values: ..T) -> T {…}
     

    min returns the minimum value of passed arguments of all the same type. If one argument is passed and it is an enum or numeric type, then min returns the minimum value of the enum type's fields or its minimum / most negative numeric value respectively.

    offset_of ¶

    offset_of :: proc{offset_of_selector, offset_of_member} {…}
     

    offset_of returns the offset in bytes with the struct of the field.

    offset_of_by_string ¶

    offset_of_by_string :: proc($T: typeid, member: string) -> uintptr {…}
     

    e.g. offset_of(T, "f"), where T can be the type instead of a variable

    offset_of_member ¶

    offset_of_member :: proc($T: typeid, member: $M) -> uintptr {…}
     

    e.g. offset_of(T, f), where T can be the type instead of a variable

    offset_of_selector ¶

    offset_of_selector :: proc(selector: $T) -> uintptr {…}
     

    e.g. offset_of(t.f), where t is an instance of the type T

    quaternion ¶

    quaternion :: proc(real, imag, jmag, kmag: Float) -> Quaternion_Type {…}
     

    raw_data ¶

    raw_data :: proc(value: $T) -> [^]$E {…}
     

    raw_data returns the underlying data of a built-in data type as a multi-pointer.

    raw_data([]$E)         -> [^]E    // slices
    raw_data([dynamic]$E)  -> [^]E    // dynamic arrays
    raw_data(^[$N]$E)      -> [^]E    // fixed array and enumerated arrays 
    raw_data(^#simd[$N]$E) -> [^]E    // simd vectors 
    raw_data(string)       -> [^]byte // string
    

    real ¶

    real :: proc(v: Complex_Or_Quaternion) -> Float {…}
     

    real returns the real part of a complex or quaternion number v. The return value will be the floating-point type corresponding to the type of v.

    size_of ¶

    size_of :: proc($T: typeid) -> int {…}
     

    size_of takes an expression or type, and returns the size in bytes of the type of the expression if it was hypothetically instantiated as a variable. The size does not include any memory possibly referenced by a value. For instance, if a slice was given, size_of returns the size of the internal slice data structure and not the size of the memory referenced by the slice. For a struct, the size includes any padding introduced by field alignment (if not specified with #packed. Other types follow similar rules. The return value of size_of is a compile time known integer constant.

    soa_unzip ¶

    soa_unzip :: proc(value: $S/#soa[]$E) -> (slices: ...) {…}
     

    See: https://odin-lang.org/docs/overview/#soa_zip-and-soa_unzip

    soa_zip ¶

    soa_zip :: proc(slices: ...) -> #soa[]Struct {…}
     

    See: https://odin-lang.org/docs/overview/#soa_zip-and-soa_unzip

    swizzle ¶

    swizzle :: proc(x: [N]T, indices: ..int) -> [len(indices)]T {…}
     

    type_info_of ¶

    type_info_of :: proc($T: typeid) -> ^runtime.Type_Info {…}
     

    type_info_of returns the runtime type information from a given typeid.

    type_of ¶

    type_of :: proc(x: expr) -> type {…}
     

    type_of returns the type of a given expression

    typeid_of ¶

    typeid_of :: proc($T: typeid) -> typeid {…}
     

    typeid_of returns the associated runtime known typeid of the specified type.

    append_elem ¶

    append_elem :: proc(array: ^$T/[dynamic]$E, #no_broadcast arg: $E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    append_elem appends an element to the end of a dynamic array.

    append_elem_string ¶

    append_elem_string :: proc(array: ^[dynamic]u8, arg: string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    append_elem_string appends a string to the end of a dynamic array of bytes

    Note: Prefer using the procedure group append.

    append_elems ¶

    append_elems :: proc(array: ^$T/[dynamic]$E, .. #no_broadcast args: $T/..$E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    append_elems appends args to the end of a dynamic array.

    Note: Prefer using the procedure group append.

    append_nothing ¶

    append_nothing :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    append_nothing appends an empty value to a dynamic array. It returns 1, nil if successful, and 0, err when it was not possible, whatever err happens to be.

    append_soa_elem ¶

    append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast arg: $E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}

    append_soa_elems ¶

    append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, .. #no_broadcast args: $T/..$E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}

    append_string ¶

    append_string :: proc(array: ^[dynamic]u8, .. args: ..string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    The append_string built-in procedure appends multiple strings to the end of a [dynamic]u8 like type

    Note: Prefer using the procedure group append.

    assert ¶

    assert :: proc(condition: bool, message: string = #caller_expression(condition), loc := #caller_location) {…}
     

    Evaluates the condition and panics the program iff the condition is false. This uses the context.assertion_failure_procedure to assert.

    This routine will be ignored when ODIN_DISABLE_ASSERT is true.

    assert_contextless ¶

    assert_contextless :: proc "contextless" (condition: bool, message: string = #caller_expression(condition), loc := #caller_location) {…}
     

    Evaluates the condition and panics the program iff the condition is false. This uses the default_assertion_contextless_failure_proc to assert.

    This routine will be ignored when ODIN_DISABLE_ASSERT is true.

    assign_at_elem ¶

    assign_at_elem :: proc(array: ^$T/[dynamic]$E, #any_int index: int, #no_broadcast arg: $E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
     

    assign_at_elem assigns a value at a given index. If the requested index is smaller than the current size of the dynamic array, it will attempt to resize the a new length of index+1 and then assign as index.

    assign_at_elem_string ¶

    assign_at_elem_string :: proc(array: ^[dynamic]u8, #any_int index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
     

    assign_at_elem_string assigns a string at a given index. If the requested index is smaller than the current size of the dynamic array, it will attempt to resize the a new length of index+len(arg) and then assign as index.

    assign_at_elems ¶

    assign_at_elems :: proc(array: ^$T/[dynamic]$E, #any_int index: int, .. #no_broadcast args: $T/..$E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
     

    assign_at_elems assigns a values at a given index. If the requested index is smaller than the current size of the dynamic array, it will attempt to resize the a new length of index+len(args) and then assign as index.

    card ¶

    card :: proc "contextless" (s: $T/bit_set[$E]) -> int {…}
     

    card returns the number of bits that are set in a bit_set—its cardinality

    clear_dynamic_array ¶

    clear_dynamic_array :: proc "contextless" (array: ^$T/[dynamic]$E) {…}
     

    clear_dynamic_array will set the length of a passed dynamic array to 0

    Note: Prefer the procedure group clear.

    clear_map ¶

    clear_map :: proc "contextless" (m: ^$T/map[$K]$V) {…}
     

    clear_map will set the length of a passed map to 0

    Note: Prefer the procedure group clear

    container_of ¶

    container_of :: proc "contextless" (ptr: $P/^$Field_Type, $T: typeid, $field_name: string) -> ^typeid {…}
     

    Recovers the containing/parent struct from a pointer to one of its fields. Works by "walking back" to the struct's starting address using the offset between the field and the struct.

    Inputs:
    ptr: Pointer to the field of a container struct T: The type of the container struct field_name: The name of the field in the T struct

    Returns:
    A pointer to the container struct based on a pointer to a field in it

    Example:
    package container_of
    import "base:runtime"
    
    Node :: struct {
    	value: int,
    	prev:  ^Node,
    	next:  ^Node,
    }
    
    main :: proc() {
    	node: Node
    	field_ptr := &node.next
    	container_struct_ptr: ^Node = runtime.container_of(field_ptr, Node, "next")
    	assert(container_struct_ptr == &node)
    	assert(uintptr(field_ptr) - uintptr(container_struct_ptr) == size_of(node.value) + size_of(node.prev))
    }
    
    Output:
    ^Node
    

    copy_from_string ¶

    copy_from_string :: proc "contextless" (dst: []u8, src: string) -> int {…}
     

    copy_from_string is a built-in procedure that copies elements from a source string src to a destination slice dst. The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum of len(src) and len(dst).

    Prefer the procedure group copy.

    copy_from_string16 ¶

    copy_from_string16 :: proc "contextless" (dst: []u16, src: string16) -> int {…}
     

    copy_from_string16 is a built-in procedure that copies elements from a source string src to a destination slice dst. The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum of len(src) and len(dst).

    Prefer the procedure group copy.

    copy_slice ¶

    copy_slice :: proc "contextless" (dst, src: $T/[]$E) -> int {…}
     

    copy_slice is a built-in procedure that copies elements from a source slice src to a destination slice dst. The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum of len(src) and len(dst).

    Prefer the procedure group copy.

    delete_cstring ¶

    delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}
     

    delete_cstring will try to free the underlying data of the passed string, with the given allocator if the allocator supports this operation.

    Note: Prefer the procedure group delete.

    delete_cstring16 ¶

    delete_cstring16 :: proc(str: cstring16, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}

    delete_dynamic_array ¶

    delete_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) -> Allocator_Error {…}
     

    delete_dynamic_array will try to free the underlying data of the passed dynamic array, with the given allocator if the allocator supports this operation.

    Note: Prefer the procedure group delete.

    delete_key ¶

    delete_key :: proc(m: ^$T/map[$K]$V, key: $K) -> (deleted_key: $K, deleted_value: $V) {…}
     

    The delete_key built-in procedure deletes the element with the specified key (m[key]) from the map. If m is nil, or there is no such element, this procedure is a no-op

    delete_map ¶

    delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) -> Allocator_Error {…}
     

    delete_map will try to free the underlying data of the passed map, with the given allocator if the allocator supports this operation.

    Note: Prefer the procedure group delete.

    delete_slice ¶

    delete_slice :: proc(array: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}
     

    delete_slice will try to free the underlying data of the passed sliced, with the given allocator if the allocator supports this operation.

    Note: Prefer the procedure group delete.

    delete_string ¶

    delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}
     

    delete_string will try to free the underlying data of the passed string, with the given allocator if the allocator supports this operation.

    Note: Prefer the procedure group delete.

    delete_string16 ¶

    delete_string16 :: proc(str: string16, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {…}

    ensure ¶

    ensure :: proc(condition: bool, message: string = #caller_expression(condition), loc := #caller_location) {…}
     

    Evaluates the condition and panics the program iff the condition is false. This uses the context.assertion_failure_procedure to assert. This routine ignores ODIN_DISABLE_ASSERT, and will always execute.

    ensure_contextless ¶

    ensure_contextless :: proc "contextless" (condition: bool, message: string = #caller_expression(condition), loc := #caller_location) {…}
     

    Evaluates the condition and panics the program iff the condition is false. This uses the default_assertion_contextless_failure_proc to assert.

    init_global_temporary_allocator ¶

    init_global_temporary_allocator :: proc(size: int, backup_allocator := context.allocator) {…}
     

    Initializes the global temporary allocator used as the default context.temp_allocator. This is ignored when NO_DEFAULT_TEMP_ALLOCATOR is true.

    inject_at_elem ¶

    inject_at_elem :: proc(array: ^$T/[dynamic]$E, #any_int index: int, #no_broadcast arg: $E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
     

    inject_at_elem injects an element in a dynamic array at a specified index and moves the previous elements after that index "across"

    inject_at_elem_string ¶

    inject_at_elem_string :: proc(array: ^[dynamic]u8, #any_int index: int, arg: string, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
     

    inject_at_elem_string injects a string into a dynamic array at a specified index and moves the previous elements after that index "across"

    inject_at_elems ¶

    inject_at_elems :: proc(array: ^$T/[dynamic]$E, #any_int index: int, .. #no_broadcast args: $T/..$E, loc := #caller_location) -> (ok: bool, err: Allocator_Error) #optional_ok {…}
     

    inject_at_elems injects multiple elements in a dynamic array at a specified index and moves the previous elements after that index "across"

    make_dynamic_array ¶

    make_dynamic_array :: proc($T: typeid/[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
     

    make_dynamic_array allocates and initializes a dynamic array. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    Note: Prefer using the procedure group make.

    make_dynamic_array_len ¶

    make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}
     

    make_dynamic_array_len allocates and initializes a dynamic array. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    Note: Prefer using the procedure group make.

    make_dynamic_array_len_cap ¶

    make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) {…}
     

    make_dynamic_array_len_cap allocates and initializes a dynamic array. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    Note: Prefer using the procedure group make.

    make_map ¶

    make_map :: proc($T: typeid/map[$K]$E, allocator := context.allocator, loc := #caller_location) -> (m: $/map[$K]$E) {…}
     

    make_map initializes a map with an allocator. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    Note: Prefer using the procedure group make.

    make_map_cap ¶

    make_map_cap :: proc($T: typeid/map[$K]$E, #any_int capacity: int, allocator := context.allocator, loc := #caller_location) -> (m: $/map[$K]$E, err: Allocator_Error) #optional_ok {…}
     

    make_map_cap initializes a map with an allocator and allocates space using capacity. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    Note: Prefer using the procedure group make.

    make_multi_pointer ¶

    make_multi_pointer :: proc($T: typeid/[^]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (mp: $/[^]$E, err: Allocator_Error) {…}
     

    make_multi_pointer allocates and initializes a multi-pointer. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    This is "similar" to doing raw_data(make([]E, len, allocator)).

    Note: Prefer using the procedure group make.

    make_slice ¶

    make_slice :: proc($T: typeid/[]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (res: T, err: Allocator_Error) #optional_ok {…}
     

    make_slice allocates and initializes a slice. Like new, the first argument is a type, not a value. Unlike new, make's return value is the same as the type of its argument, not a pointer to it.

    Note: Prefer using the procedure group make.

    make_soa_aligned ¶

    make_soa_aligned :: proc($T: typeid/#soa[]$E, #any_int length, #any_int alignment: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}

    make_soa_dynamic_array ¶

    make_soa_dynamic_array :: proc($T: typeid/#soa[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) {…}

    make_soa_dynamic_array_len ¶

    make_soa_dynamic_array_len :: proc($T: typeid/#soa[dynamic]$E, #any_int length: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}

    make_soa_dynamic_array_len_cap ¶

    make_soa_dynamic_array_len_cap :: proc($T: typeid/#soa[dynamic]$E, #any_int length, #any_int capacity: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}

    make_soa_slice ¶

    make_soa_slice :: proc($T: typeid/#soa[]$E, #any_int length: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_ok {…}

    map_entry ¶

    map_entry :: proc(m: ^$T/map[$K]$V, key: $K, loc := #caller_location) -> (key_ptr: ^$K, value_ptr: ^$V, just_inserted: bool, err: Allocator_Error) {…}
     

    Retrieves a pointer to the key and value for a possibly just inserted entry into the map.

    If the key was not in the map m, an entry is inserted with the zero value and just_inserted will be true. Otherwise the existing entry is left untouched and pointers to its key and value are returned.

    If the map has to grow in order to insert the entry and the allocation fails, err is set and returned.

    If err is nil, key_ptr and value_ptr are valid pointers and will not be nil.

    WARN: User modification of the key pointed at by key_ptr should only be done if the new key is equal to (in hash) the old key. If that is not the case you will corrupt the map.

    map_insert ¶

    map_insert :: proc(m: ^$T/map[$K]$V, key: $K, value: $V, loc := #caller_location) -> (ptr: ^$V) {…}

    map_upsert ¶

    map_upsert :: proc(m: ^$T/map[$K]$V, key: $K, value: $V, loc := #caller_location) -> (prev_key: $K, value_ptr: ^$V, found_previous: bool) {…}
     

    Explicitly inserts a key and value into a map m, the same as map_insert, but the return values differ. prev_key will return the previous pointer of a key if it exists, check found_previous if was previously found value_ptr will return the pointer of the memory where the insertion happens, and nil if the map failed to resize found_previous will be true a previous key was found

    new ¶

    new :: proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> (t: ^typeid, err: Allocator_Error) #optional_ok {…}
     

    The new built-in procedure allocates memory. The first argument is a type, not a value, and the value return is a pointer to a newly allocated value of that type using the specified allocator, default is context.allocator

    new_clone ¶

    new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^$T, err: Allocator_Error) {…}

    non_zero_append_elem ¶

    non_zero_append_elem :: proc(array: ^$T/[dynamic]$E, #no_broadcast arg: $E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    non_zero_append_elem appends an element to the end of a dynamic array, without zeroing any reserved memory

    Note: Prefer using the procedure group `non_zero_append

    non_zero_append_elem_string ¶

    non_zero_append_elem_string :: proc(array: ^[dynamic]u8, arg: string, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    non_zero_append_elem_string appends a string to the end of a dynamic array of bytes, without zeroing any reserved memory

    Note: Prefer using the procedure group non_zero_append.

    non_zero_append_elems ¶

    non_zero_append_elems :: proc(array: ^$T/[dynamic]$E, .. #no_broadcast args: $T/..$E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}
     

    non_zero_append_elems appends args to the end of a dynamic array, without zeroing any reserved memory

    Note: Prefer using the procedure group `non_zero_append

    non_zero_append_soa_elem ¶

    non_zero_append_soa_elem :: proc(array: ^$T/#soa[dynamic]$E, #no_broadcast arg: $E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}

    non_zero_append_soa_elems ¶

    non_zero_append_soa_elems :: proc(array: ^$T/#soa[dynamic]$E, .. #no_broadcast args: $T/..$E, loc := #caller_location) -> (n: int, err: Allocator_Error) #optional_ok {…}

    non_zero_reserve_dynamic_array ¶

    non_zero_reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
     

    non_zero_reserve_dynamic_array will try to reserve memory of a passed dynamic array or map to the requested element count (setting the cap).

    When a memory resize allocation is required, the memory will be asked to not be zeroed (i.e. it calls non_zero_mem_resize).

    Note: Prefer the procedure group non_zero_reserve.

    non_zero_reserve_soa ¶

    non_zero_reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}

    non_zero_resize_dynamic_array ¶

    non_zero_resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}
     

    non_zero_resize_dynamic_array will try to resize memory of a passed dynamic array or map to the requested element count (setting the len, and possibly cap).

    When a memory resize allocation is required, the memory will be asked to not be zeroed (i.e. it calls non_zero_mem_resize).

    Note: Prefer the procedure group non_zero_resize

    non_zero_resize_soa ¶

    non_zero_resize_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}

    ordered_remove ¶

    ordered_remove :: proc(array: ^[dynamic]$T, #any_int index: int, loc := #caller_location) {…}
     

    ordered_remove removed the element at the specified index whilst keeping the order of the other elements.

    Note: This is an O(N) operation. Note: If the elements do not have to remain in their order, prefer unordered_remove. Note: If the index is out of bounds, this procedure will panic.

    ordered_remove_soa ¶

    ordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int index: int, loc := #caller_location) {…}
     

    ordered_remove_soa removed the element at the specified index whilst keeping the order of the other elements.

    Note: This is an O(N) operation. Note: If you the elements do not have to remain in their order, prefer unordered_remove_soa. Note: If the index is out of bounds, this procedure will panic.

    panic ¶

    panic :: proc(message: string, loc := #caller_location) -> ! {…}
     

    Panics the program with a message. This uses the context.assertion_failure_procedure to panic.

    panic_contextless ¶

    panic_contextless :: proc "contextless" (message: string, loc := #caller_location) -> ! {…}
     

    Panics the program with a message to indicate something has yet to be implemented. This uses the default_assertion_contextless_failure_proc to assert.

    pop ¶

    pop :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: $E) {…}
     

    pop will remove and return the end value of dynamic array array and reduces the length of array by 1.

    Note: If the dynamic array has no elements (len(array) == 0), this procedure will panic.

    pop_front ¶

    pop_front :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: $E) {…}
     

    pop_front will remove and return the first value of dynamic array array and reduces the length of array by 1.

    Note: If the dynamic array as no elements (len(array) == 0), this procedure will panic.

    pop_front_safe ¶

    pop_front_safe :: proc "contextless" (array: ^$T/[dynamic]$E) -> (res: $E, ok: bool) {…}
     

    pop_front_safe trys to return and remove the first value of dynamic array array and reduces the length of array by 1. If the operation is not possible, it will return false.

    pop_safe ¶

    pop_safe :: proc "contextless" (array: ^$T/[dynamic]$E) -> (res: $E, ok: bool) {…}
     

    pop_safe trys to remove and return the end value of dynamic array array and reduces the length of array by 1. If the operation is not possible, it will return false.

    raw_soa_footer_dynamic_array :: proc(array: ^$T/#soa[dynamic]$E) -> (footer: ^Raw_SOA_Footer_Dynamic_Array) {…}
    raw_soa_footer_slice :: proc(array: ^$T/#soa[]$E) -> (footer: ^Raw_SOA_Footer_Slice) {…}

    remove_range ¶

    remove_range :: proc(array: ^[dynamic]$T, #any_int lo, #any_int hi: int, loc := #caller_location) {…}
     

    remove_range removes a range of elements specified by the range lo and hi, whilst keeping the order of the other elements.

    Note: This is an O(N) operation. Note: If the range is out of bounds, this procedure will panic.

    reserve_dynamic_array ¶

    reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
     

    reserve_dynamic_array will try to reserve memory of a passed dynamic array or map to the requested element count (setting the cap).

    When a memory resize allocation is required, the memory will be asked to be zeroed (i.e. it calls mem_resize).

    Note: Prefer the procedure group reserve.

    reserve_map ¶

    reserve_map :: proc(m: ^$T/map[$K]$V, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}
     

    reserve_map will try to reserve memory of a passed map to the requested element count (setting the cap).

    Note: Prefer the procedure group reserve

    reserve_soa ¶

    reserve_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int capacity: int, loc := #caller_location) -> Allocator_Error {…}

    resize_dynamic_array ¶

    resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}
     

    resize_dynamic_array will try to resize memory of a passed dynamic array or map to the requested element count (setting the len, and possibly cap).

    When a memory resize allocation is required, the memory will be asked to be zeroed (i.e. it calls mem_resize).

    Note: Prefer the procedure group resize

    resize_soa ¶

    resize_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int length: int, loc := #caller_location) -> Allocator_Error {…}

    shrink_map ¶

    shrink_map :: proc(m: ^$T/map[$K]$V, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {…}
     

    Shrinks the capacity of a map down to the current length.

    Note: Prefer the procedure group shrink

    unimplemented ¶

    unimplemented :: proc(message: string = "", loc := #caller_location) -> ! {…}
     

    Panics the program with a message to indicate something has yet to be implemented. This uses the context.assertion_failure_procedure to assert.

    unimplemented_contextless ¶

    unimplemented_contextless :: proc "contextless" (message: string = "", loc := #caller_location) -> ! {…}
     

    Panics the program with a message. This uses the default_assertion_contextless_failure_proc to assert.

    unordered_remove ¶

    unordered_remove :: proc(array: ^[dynamic]$T, #any_int index: int, loc := #caller_location) {…}
     

    unordered_remove removed the element at the specified index. It does so by replacing the current end value with the old value, and reducing the length of the dynamic array by 1.

    Note: This is an O(1) operation. Note: If you want the elements to remain in their order, use ordered_remove. Note: If the index is out of bounds, this procedure will panic.

    unordered_remove_soa ¶

    unordered_remove_soa :: proc(array: ^$T/#soa[dynamic]$E, #any_int index: int, loc := #caller_location) {…}
     

    unordered_remove_soa removed the element at the specified index. It does so by replacing the current end value with the old value, and reducing the length of the dynamic array by 1.

    Note: This is an O(1) operation. Note: If you the elements to remain in their order, use ordered_remove_soa. Note: If the index is out of bounds, this procedure will panic.

    Procedure Groups

    append ¶

     

    The append built-in procedure appends elements to the end of a dynamic array

    append_soa ¶

    append_soa :: proc{
    	append_soa_elem,
    	append_soa_elems,
    }
    
     

    The append_soa built-in procedure appends elements to the end of an #soa dynamic array

    assign_at ¶

     

    assign_at assigns a value at a given index. If the requested index is smaller than the current size of the dynamic array, it will attempt to resize the a new length of index+size_needed and then assign as index.

    clear ¶

     

    clear will set the length of a passed dynamic array or map to 0

    copy ¶

     

    copy is a built-in procedure that copies elements from a source slice/string src to a destination slice dst. The source and destination may overlap. Copy returns the number of elements copied, which will be the minimum of len(src) and len(dst).

    delete ¶

     

    delete will try to free the underlying data of the passed built-in data structure (string, cstring, dynamic array, slice, or map), with the given allocator if the allocator supports this operation.

    Note: Prefer delete over the specific delete_* procedures where possible.

    free ¶

    free :: proc{
    	mem_free,
    }
    
     

    free will try to free the passed pointer, with the given allocator if the allocator supports this operation.

    free_all ¶

    free_all :: proc{
    	mem_free_all,
    }
    
     

    free_all will try to free/reset all of the memory of the given allocator if the allocator supports this operation.

    inject_at ¶

     

    inject_at injects something into a dynamic array at a specified index and moves the previous elements after that index "across"

    make ¶

     

    make built-in procedure allocates and initializes a value of type slice, dynamic array, map, or multi-pointer (only).

    Similar to new, the first argument is a type, not a value. Unlike new, make's return type is the same as the type of its argument, not a pointer to it. Make uses the specified allocator, default is context.allocator.

    reserve ¶

     

    reserve will try to reserve memory of a passed dynamic array or map to the requested element count (setting the cap).

    resize ¶

    resize :: proc{
    	resize_dynamic_array,
    	resize_soa,
    }
    
     

    resize will try to resize memory of a passed dynamic array to the requested element count (setting the len, and possibly cap).

    shrink ¶

    shrink :: proc{
    	shrink_dynamic_array,
    	shrink_map,
    }
    
     

    Shrinks the capacity of a dynamic array or map down to the current length, or the given capacity.