Why is the size of this union larger than expected?

const std = @import("std");

const AUnion = union { field1: u64, field2: u64, field3: u64 };

pub fn main() void {
    std.log.info("{}", .{@sizeOf(AUnion)});
}

Prints info: 16.

Judging by the fields in the union, the size of the union should be 8 bytes. Does anyone know why this is 16?

Untagged unions still have a hidden tag for safety checks. Have you tried building with ReleaseFast or ReleaseSmall?

2 Likes