mirror of
https://github.com/golang/go
synced 2024-11-21 20:54:45 -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:
parent
1d6eb74697
commit
934a520d75
@ -1,5 +1,5 @@
|
||||
<!-- title The Go Programming Language Specification -->
|
||||
<!-- subtitle Version of May 14, 2010 -->
|
||||
<!-- subtitle Version of May 24, 2010 -->
|
||||
|
||||
<!--
|
||||
Todo
|
||||
@ -3254,7 +3254,18 @@ that can be converted to type <code>T</code>.
|
||||
</p>
|
||||
|
||||
<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)
|
||||
<-chan int(c) // same as <-(chan int(c))
|
||||
(<-chan int)(c) // c is converted to (<-chan int)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
@ -3318,11 +3329,11 @@ string containing the UTF-8 representation of the integer.
|
||||
Negative values are converted to <code>"\uFFFD"</code>.
|
||||
|
||||
<pre>
|
||||
string('a') // "a"
|
||||
string(-1) // "\ufffd" == "\xef\xbf\xbd "
|
||||
string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8"
|
||||
string('a') // "a"
|
||||
string(-1) // "\ufffd" == "\xef\xbf\xbd "
|
||||
string(0xf8) // "\u00f8" == "ø" == "\xc3\xb8"
|
||||
type MyString string
|
||||
MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
|
||||
MyString(0x65e5) // "\u65e5" == "日" == "\xe6\x97\xa5"
|
||||
</pre>
|
||||
</li>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user