Unions

Just like structs, unions support embedding.

struct Rgba32_Component { r u8 g u8 b u8 a u8 } union Rgba32 { Rgba32_Component value u32 } clr1 := Rgba32{ value: 0x008811FF } clr2 := Rgba32{ Rgba32_Component: Rgba32_Component{ a: 128 } } sz := sizeof(Rgba32) unsafe { println('Size: ${sz}B,clr1.b: ${clr1.b},clr2.b: ${clr2.b}') }

Output: Size: 4B, clr1.b: 136, clr2.b: 0

Union member access must be performed in an unsafe block.

[!NOTE] Embedded struct arguments are not necessarily stored in the order listed.