Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The articles states:

>"It's OK to call a pointer receiver method on a value as long as the value is addressable. In other words, you don't need to have a value receiver version of the method in some cases.

Not every variable is addressable though. Map elements are not addressable."

Since everything in memory has an address I am confused by these statements. Does the author mean that "not everything can be pointed to" with a pointer variable in Go?



Go itself says you "cannot take the address" of some values. For example:

  m := map[int]int{1: 2}
  p := &m[1]
The second line causes the compilation error "cannot take the address of m[1]".

https://play.golang.org/p/pIMgeQzOSZK


Thanks, I think it was the wording "addressable" that was the source of my confusion. "cannot take the address of" seems more intuitive to me. Cheers.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: