Standard library / unsafe

unsafe.Alignof()

Reports the required alignment of a hypothetical variable of the expression’s type, or the field alignment when the operand is a struct field. It is not the alignment of a particular runtime address. Fixed-size types yield constants. Signatures use documentation-only placeholders where applicable; these are compiler intrinsics, not ordinary function values. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Alignof(x ArbitraryType) uintptr

Parameters & Attributes

NameTypeDescription
xArbitraryTypeExpression of the type or struct field whose required alignment is queried.

Return Value

uintptr

Required byte alignment.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect"  "unsafe")
func main() {  var n uint64  fmt.Println(unsafe.Alignof(n) == uintptr(reflect.TypeOf(n).Align()))}
Go Reference