When running this program:
package main
import (
"fmt"
)
type Foo struct {
i int
}
func main() {
var f1 = &Foo{i: 0}
var f2 = &(*f1)
f2.i = 1
fmt.Println(f1, f2)
}
it yields:
&{1} &{1}
(https://play.golang.org/p/qKtURokUCEW)
I (naively) assumed that the expression
&(*f1)
would, first, create a copy of *f1, and then a pointer to that copy, but
evidently f2 becomes a pointer to the same struct as f1. Is this something
I should have deduced from the language spec?
best regards Christian Surlykke
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/f427ddf6-f4fc-42f4-bee8-d1dab0fef566n%40googlegroups.com.