News for hackers. Stuff that matters.
Re:Things I Wish Someone Had Told Me About Go by pdw on Monday March 11, 2013 @12:52PM (#5357959)
You don't need pointer-to-pointers to replace the entire struct, you can just do this: http://play.golang.org/p/2ZUvuyCtwr

  func main() {
    u := &User{Name: "Leto"}
    println(u.Name)
    Modify(u)
    println(u.Name)
  }
  
  func Modify(u *User) {
    *u = User{Name: "Paul"}
  }
Re:Things I Wish Someone Had Told Me About Go by Rygu on Monday March 11, 2013 @07:08PM (#5359357)
Looks like C pointer syntax!
Re:Things I Wish Someone Had Told Me About Go by ithkuil on Tuesday March 12, 2013 @05:48AM (#5361004)
Indeed. They are pointers. You just cannot do pointer arithmetic on them.

In declaration the '' goes on the left though. In general Go's syntax inverts the declaration w.r.t C/C++:

    a int   vs  int  a
    b *int  vs  int* b

    type X int  vs  typedef int X
NOTE: you can do unsafe pointer arithmetic using the "unsafe" package. You can convert any pointer to a unsafe.Pointer and then you can convert it to a uintptr.

There are also library functions designed to work with that, for example atomic.AddUintptr that atomically adds an offset to a pointer.

Although not intended as general use, it can be useful in low level library code. Otherwise you can do pretty much everything using slices.

Re:Things I Wish Someone Had Told Me About Go by fmstephe on Monday March 11, 2013 @05:34PM (#5359318)
Good point. Thx :)