]> Cypherpunks repositories - gostls13.git/commitdiff
spec: clarify that any unsafe.Pointer type is okay in conversion
authorRuss Cox <rsc@golang.org>
Sat, 9 Feb 2013 22:36:31 +0000 (17:36 -0500)
committerRuss Cox <rsc@golang.org>
Sat, 9 Feb 2013 22:36:31 +0000 (17:36 -0500)
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

doc/go_spec.html

index 30c9a9766cd483fce876199bd6a6f621e8fabea0..f18585a2e9c3d9b1fa3e94f0a86fc52e2b900749 100644 (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>