1
0
mirror of https://github.com/golang/go synced 2024-11-24 18:00:02 -07:00

go spec: fix and clarify syntax of conversions

Fixes #803.

R=rsc, r, iant, ken2
CC=golang-dev
https://golang.org/cl/1281041
This commit is contained in:
Robert Griesemer 2010-05-24 14:58:26 -07:00
parent 1d6eb74697
commit 934a520d75

View File

@ -1,5 +1,5 @@
<!-- title The Go Programming Language Specification --> <!-- title The Go Programming Language Specification -->
<!-- subtitle Version of May 14, 2010 --> <!-- subtitle Version of May 24, 2010 -->
<!-- <!--
Todo Todo
@ -3254,7 +3254,18 @@ that can be converted to type <code>T</code>.
</p> </p>
<pre class="ebnf"> <pre class="ebnf">
Conversion = LiteralType "(" Expression ")" . Conversion = Type "(" Expression ")" .
</pre>
<p>
If the type starts with an operator it must be parenthesized:
</p>
<pre>
*Point(p) // same as *(Point(p))
(*Point)(p) // p is converted to (*Point)
&lt;-chan int(c) // same as &lt;-(chan int(c))
(&lt;-chan int)(c) // c is converted to (&lt;-chan int)
</pre> </pre>
<p> <p>
@ -3318,11 +3329,11 @@ string containing the UTF-8 representation of the integer.
Negative values are converted to <code>"\uFFFD"</code>. Negative values are converted to <code>"\uFFFD"</code>.
<pre> <pre>
string('a') // "a" string('a') // "a"
string(-1) // "\ufffd" == "\xef\xbf\xbd " string(-1) // "\ufffd" == "\xef\xbf\xbd "
string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8" string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8"
type MyString string type MyString string
MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5" MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
</pre> </pre>
</li> </li>