Unions in Odin

Table of Contents

1. Raw Unions as in C

To mimic the unions in C, we should declare with struct keyword and raw union tags. Since in C, there’s no auxiliary ways to track the variant, so we usually need to manually track.

  RawUnion :: struct #raw_union {
      number: int,
      struct_val: MyStruct,
  }

  a_raw_union: RawUnion,

2. Unions as State Machines

Date: 2026-07-17 Fri