From 89c59bc6f6bb8af66e8fb290c57081a18000f9cf Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Wed, 11 May 2011 08:31:24 -0700 Subject: [PATCH] effective go: explain about values/pointers in String() example Fixes #1796. R=rsc, r2, niemeyer CC=golang-dev https://golang.org/cl/4539049 --- doc/effective_go.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/effective_go.html b/doc/effective_go.html index 1aeed4ad84e..86b2d63dcba 100644 --- a/doc/effective_go.html +++ b/doc/effective_go.html @@ -1489,6 +1489,12 @@ to print in the format 7/-2.35/"abc\tdef"

+(If you need to print values of type T as well as pointers to T, +the receiver for String 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 pointers vs. value receivers for more information.) +

+

Our String() method is able to call Sprintf 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.