Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Function

alignPointer

Public Function
std.mem.alignPointer
pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr)

Aligns a given pointer value to a specified alignment factor. Returns an aligned pointer or null if one of the following conditions is met:

  • The aligned pointer would not fit the address space,
  • The delta required to align the pointer is not a multiple of the pointee's type.

Params

  • ptr
  • align_to: usize

File

mem.zig:4334
4334
4335
4336
4337
4338
pub fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr) {
    const adjust_off = alignPointerOffset(ptr, align_to) orelse return null;
    // Avoid the use of ptrFromInt to avoid losing the pointer provenance info.
    return @alignCast(ptr + adjust_off);
}