diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2016-08-17 16:23:40 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2016-08-18 16:45:17 +0000 |
commit | 29df4c8f0004aa259093bf8dbf0bf966a392d44d (patch) | |
tree | 0fb2284359a0e5bcef1c256e1c588b0e4328a9bf /src/unsafe | |
parent | a7277e5494c696a4798b99e1e55d55acf61211de (diff) | |
download | go-29df4c8f0004aa259093bf8dbf0bf966a392d44d.tar.gz go-29df4c8f0004aa259093bf8dbf0bf966a392d44d.zip |
unsafe: document use of &^ to round/align pointers
Follow-up to CL 27156
Change-Id: I4f1cfced2dced9c9fc8a05bbc00ec4229e85c5c9
Reviewed-on: https://go-review.googlesource.com/27314
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/unsafe')
-rw-r--r-- | src/unsafe/unsafe.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/unsafe/unsafe.go b/src/unsafe/unsafe.go index 8f43e72775..0b59ff204b 100644 --- a/src/unsafe/unsafe.go +++ b/src/unsafe/unsafe.go @@ -76,8 +76,10 @@ type ArbitraryType int // // equivalent to e := unsafe.Pointer(&x[i]) // e := unsafe.Pointer(uintptr(unsafe.Pointer(&x[0])) + i*unsafe.Sizeof(x[0])) // -// It is valid both to add and to subtract offsets from a pointer in this way, -// but the result must continue to point into the original allocated object. +// It is valid both to add and to subtract offsets from a pointer in this way. +// It is also valid to use &^ to round pointers, usually for alignment. +// In all cases, the result must continue to point into the original allocated object. +// // Unlike in C, it is not valid to advance a pointer just beyond the end of // its original allocation: // |