If you assign a pointer value, a copy of that pointer value is made.
The thing the pointer points at is not copied.
> type Pet structure {...}
>
> var huski Pet = new(Pet)
> dog := huski
This code won't compile. new(Pet) returns a value of type *Pet, while
the variable huski is of type Pet.
In this example, huski and dog are both pointers to the same Pet:
var huski *Pet = new(Pet)
dog := huski
In this example, dog is a copy of huski, which is a Pet value:
var huski Pet = Pet{}
dog := huski
You can then modify the huski value without affecting dog.
Andrew
This is really an implementation detail More than a spec detail. Slices and friends are for specification purposes a reference type. I believe That currently they're actually an underlying structure passed by value and the structure contains a pointer to the referenced data. Iirc
On 9 Jan 2011 20:15, "Ostsol" <ost...@gmail.com> wrote:
Addendum: even pointers are simply values, and as such are passed by
value. A map, slice, or channel is a pointer to underlying data, but
it is a pointer that cannot be dereferenced, like other pointers. It
is best to program in Go not thinking in terms of Java or Python, but
C.
-Daniel
On Jan 9, 6:08 pm, Ostsol <ost...@gmail.com> wrote:
> In Go, almost everything is passed by value. ...