Skip to content

Instantly share code, notes, and snippets.

@Tracnac
Last active June 18, 2026 07:26
Show Gist options
  • Select an option

  • Save Tracnac/fc19a3d81496ac7dc018949cca87371d to your computer and use it in GitHub Desktop.

Select an option

Save Tracnac/fc19a3d81496ac7dc018949cca87371d to your computer and use it in GitHub Desktop.
Odin quick ref
Category Examples Notes
Basic int, u64, f64, bool, byte, string, rune Explicit sizes: i8, u16, f32, etc.
Array 4int, NT Fixed-length, value type
Slice []int Pointer+len, reference semantics
Dynamic array dynamicint Heap-backed, growable
Struct struct { x: int } Value type, can have methods via proc(s: ^T)
Union union { int, bool } Tagged or raw
Enum enum { A, B } Can have explicit values
Pointer ^T Pointer to T
Multi-pointer ^T C-style untyped-length pointer
Procedure proc(x: int) -> bool First-class, type_of to alias
Type alias MyInt :: int Not a new type
Distinct MyInt :: distinct int New type, no implicit conversion
Maybe Maybe(T) Optional -- nil or T
Any any Type-erased box (like interface{})
Construct Syntax Notes
If if cond { } else if cond { } else { } No parentheses around condition, braces required
For-range for key, val in container { } Works on slices, arrays, maps, strings, channels
For-condition for cond { } No parens, equivalent to while
For-infinite for { } No condition = infinite loop
For-C-style for i := 0, i < n, i += 1 { } All three parts optional
Switch switch x { case 1: ... case 2: ... } No fallthrough by default, use fallthrough explicitly
Switch-capture switch v in value { case 1: ... } Binds the scrutinee
Expr-switch switch { case cond: ... } Like if-else chain
Defer defer expr Runs at scope exit (LIFO stack)
Branch break, continue, fallthrough Standard semantics
When when ODIN_OS == "darwin" { } Compile-time conditional
Return return val Explicit, multiple returns: return a, b, true
Or-else val := expr or_else fallback Unwrap Maybe(T) with default
Or-return val := expr or_return Unwrap Maybe(T) or return from proc
Type Syntax Notes
Struct struct { x: int, y: f64 } Value type, fields comma/semicolon separated, no inheritance
Struct literal MyStruct{ x = 1, y = 2.0 } Named field syntax, positional also works
Struct packing struct #packed{ x: u8, y: u32 } No padding between fields
Struct alignment struct #align(N) { x: u8, y: u32 } Minimum alignment N
Struct raw-union struct #raw_union { x: u8, y: u32 } Fields overlap in memory (like C union)
Union union { int, bool, string } Tagged by default -- runtime discriminates
Union literal union_val: union { int, bool } = 42 Implicitly tagged by assigned type
Union switch switch v in union_val { case int: ... } Type-safe destructuring, compiler checks exhaustiveness
Union maybe union #no_nil{ int, bool, string, } #no_nil excludes nil from valid variants
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment