Skip to content

Commit 81eb930

Browse files
committed
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
1 parent 6ce3e99 commit 81eb930

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

doc/go_spec.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5610,9 +5610,18 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
56105610
</pre>
56115611

56125612
<p>
5613-
Any pointer or value of <a href="#Types">underlying type</a> <code>uintptr</code> can be converted into
5614-
a <code>Pointer</code> and vice versa.
5613+
Any pointer or value of <a href="#Types">underlying type</a> <code>uintptr</code> can be converted to
5614+
a <code>Pointer</code> type and vice versa.
56155615
</p>
5616+
5617+
<pre>
5618+
var f float64
5619+
bits = *(*uint64)(unsafe.Pointer(&amp;f))
5620+
5621+
type ptr unsafe.Pointer
5622+
bits = *(*uint64)(ptr(&amp;f))
5623+
</pre>
5624+
56165625
<p>
56175626
The functions <code>Alignof</code> and <code>Sizeof</code> take an expression <code>x</code>
56185627
of any type and return the alignment or size, respectively, of a hypothetical variable <code>v</code>

0 commit comments

Comments
 (0)