spec: clarify that any unsafe.Pointer type is okay in conversion

The spec is not clear about whether this is allowed or not,
but both compilers allow it, because the reflect implementation
takes advantage of it. Document current behavior.

Fixes #4679.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7303064
This commit is contained in:
Russ Cox 2013-02-09 17:36:31 -05:00
parent 6ce3e99af0
commit 81eb930f7e

View file

@ -5610,9 +5610,18 @@ func Sizeof(variable ArbitraryType) uintptr
</pre>
<p>
Any pointer or value of <a href="#Types">underlying type</a> <code>uintptr</code> can be converted into
a <code>Pointer</code> and vice versa.
Any pointer or value of <a href="#Types">underlying type</a> <code>uintptr</code> can be converted to
a <code>Pointer</code> type and vice versa.
</p>
<pre>
var f float64
bits = *(*uint64)(unsafe.Pointer(&amp;f))
type ptr unsafe.Pointer
bits = *(*uint64)(ptr(&amp;f))
</pre>
<p>
The functions <code>Alignof</code> and <code>Sizeof</code> take an expression <code>x</code>
of any type and return the alignment or size, respectively, of a hypothetical variable <code>v</code>