@alignOf

@alignOf

@alignOf(comptime T: type) comptime_int

This function returns the number of bytes that this type should be aligned to for the current target to match the C ABI. When the child type of a pointer has this alignment, the alignment can be omitted from the type.

const expect = @import("std").testing.expect;
comptime {
    expect(*u32 == *align(@alignOf(u32)) u32);
}

The result is a target-specific compile time constant. It is guaranteed to be less than or equal to @sizeOf(T).

See also:

  • Alignment