3 ms·
> This prints 1234 and 1234 as you'd expect. Until it doesn't. type thing struct { foo *int } func f(x thing) { *x.foo = 42 } func main() {
by randomdata 8y ago
> This prints 1234 and 1234 as you'd expect.
Until it doesn't.
type thing struct {
foo *int
}
func f(x thing) {
*x.foo = 42
}
func main() {
v := 1234
var x thing
x.foo = &v
fmt.Printf("x.foo before: %v\n", *x.foo)
f(x)
fmt.Printf("x.foo after: %v\n", *x.foo)
}
Or maybe that is what you'd expect, but then slices shouldn't seem so mysterious.