Commit daf6f254 authored by Rob Pike's avatar Rob Pike

unsafe: document that Alignof, Offsetof, and Sizeof return a constant

Nothing is changing but the documentation, which did not mention
this property of these functions.

Fixes #27587.

Change-Id: I75bcee4a1dd9ec8cd82826c9a6e02ba7d599f719
Reviewed-on: https://go-review.googlesource.com/c/141377Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 27965c14
...@@ -178,11 +178,13 @@ type Pointer *ArbitraryType ...@@ -178,11 +178,13 @@ type Pointer *ArbitraryType
// The size does not include any memory possibly referenced by x. // The size does not include any memory possibly referenced by x.
// For instance, if x is a slice, Sizeof returns the size of the slice // For instance, if x is a slice, Sizeof returns the size of the slice
// descriptor, not the size of the memory referenced by the slice. // descriptor, not the size of the memory referenced by the slice.
// The return value of Sizeof is a Go constant.
func Sizeof(x ArbitraryType) uintptr func Sizeof(x ArbitraryType) uintptr
// Offsetof returns the offset within the struct of the field represented by x, // Offsetof returns the offset within the struct of the field represented by x,
// which must be of the form structValue.field. In other words, it returns the // which must be of the form structValue.field. In other words, it returns the
// number of bytes between the start of the struct and the start of the field. // number of bytes between the start of the struct and the start of the field.
// The return value of Offsetof is a Go constant.
func Offsetof(x ArbitraryType) uintptr func Offsetof(x ArbitraryType) uintptr
// Alignof takes an expression x of any type and returns the required alignment // Alignof takes an expression x of any type and returns the required alignment
...@@ -193,4 +195,5 @@ func Offsetof(x ArbitraryType) uintptr ...@@ -193,4 +195,5 @@ func Offsetof(x ArbitraryType) uintptr
// within that struct, then Alignof(s.f) will return the required alignment // within that struct, then Alignof(s.f) will return the required alignment
// of a field of that type within a struct. This case is the same as the // of a field of that type within a struct. This case is the same as the
// value returned by reflect.TypeOf(s.f).FieldAlign(). // value returned by reflect.TypeOf(s.f).FieldAlign().
// The return value of Alignof is a Go constant.
func Alignof(x ArbitraryType) uintptr func Alignof(x ArbitraryType) uintptr
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment