diff options
author | Ian Lance Taylor <iant@golang.org> | 2016-01-26 17:23:33 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2016-01-27 15:19:35 +0000 |
commit | f49a757ad0d8f5987953684ea20153c713f7d9b9 (patch) | |
tree | 327b74986801e249f1896b460351d6e48e0e7e96 /src/unsafe | |
parent | 867bef93b9a60ef07f068bc8d2d4398b76331e3c (diff) | |
download | go-git-f49a757ad0d8f5987953684ea20153c713f7d9b9.tar.gz |
unsafe: clarify that Alignof returns required alignment
Also document the special behavior of Alignof(s.f), and mention the
correspondence between Alignof and reflect.Type.{Align,FieldAlign}.
Change-Id: I6f81047a04c86887f1b1164473225616cae45a26
Reviewed-on: https://go-review.googlesource.com/18949
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/unsafe')
-rw-r--r-- | src/unsafe/unsafe.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index 34ca77965b..3c8cd34ae2 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -183,7 +183,12 @@ func Sizeof(x ArbitraryType) uintptr // number of bytes between the start of the struct and the start of the field. func Offsetof(x ArbitraryType) uintptr -// Alignof takes an expression x of any type and returns the alignment +// Alignof takes an expression x of any type and returns the required alignment // of a hypothetical variable v as if v was declared via var v = x. -// It is the largest value m such that the address of v is zero mod m. +// It is the largest value m such that the address of v is always zero mod m. +// It is the same as the value returned by reflect.TypeOf(x).Align(). +// As a special case, if s has a struct type and f is a field 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 value returned +// by reflect.TypeOf(s.f).FieldAlign(). func Alignof(x ArbitraryType) uintptr |