Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

alignment

Returns the alignment of type T. Note that if T is a pointer type the result is different than the one returned by @alignOf(T). If T is a pointer type the alignment of the type it points to is returned.

meta.alignment
pub fn alignment(comptime T: type) comptime_int

File

lib/std/meta.zig:34

Code

pub fn alignment(comptime T: type) comptime_int {
    return switch (@typeInfo(T)) {
        .optional => |info| switch (@typeInfo(info.child)) {
            .pointer, .@"fn" => alignment(info.child),
            else => @alignOf(T),
        },
        .pointer => |info| info.attrs.@"align" orelse @alignOf(info.child),
        else => @alignOf(T),
    };
}