]> Cypherpunks repositories - gostls13.git/commitdiff
effective go: explain about values/pointers in String() example
authorRob Pike <r@golang.org>
Wed, 11 May 2011 15:31:24 +0000 (08:31 -0700)
committerRob Pike <r@golang.org>
Wed, 11 May 2011 15:31:24 +0000 (08:31 -0700)
Fixes #1796.

R=rsc, r2, niemeyer
CC=golang-dev
https://golang.org/cl/4539049

doc/effective_go.html

index 1aeed4ad84e75648f6df11b32478e9aa4d7dd0df..86b2d63dcbaac7e1814237334abffd6a3fe27bc0 100644 (file)
@@ -1489,6 +1489,12 @@ to print in the format
 7/-2.35/"abc\tdef"
 </pre>
 <p>
+(If you need to print <em>values</em> of type <code>T</code> as well as pointers to <code>T</code>,
+the receiver for <code>String</code> must be of value type; this example used a pointer because
+that's more efficient and idiomatic for struct types.
+See the section below on <a href="#pointers_vs_values">pointers vs. value receivers</a> for more information.)
+</p>
+<p>
 Our <code>String()</code> method is able to call <code>Sprintf</code> because the
 print routines are fully reentrant and can be used recursively.
 We can even go one step further and pass a print routine's arguments directly to another such routine.