4 ms·
The word "Go" is not essential in the title.
by tapirl 10y ago
The word "Go" is not essential in the title.
- BoorishBears 10y agoIf it didn't include Go, this would barely be scratching the surface (pointer arithmetic) I see Go's pointer as closer to C#'s ref/out than anything
- jerf 10y agoI personally (emphasis intentional) consider the core distinction between "references" and "pointers" to be whether you can do pointer arithmetic on the pointers. Pointers without pointer arithmetic aren't hardly scary at all, especially in languages where there is no way to deallocate the underlying value but leave the pointer behind such that it may point to the wrong thing later, be that due to something like Rust or with GC like Go. So personally, I think of Go as having references, but not pointers (outside of unsafe). Of course every language community uses those terms its own way, but that seems to me to be the most broadly useful way of looking at it.
- steveklabnik 10y agoI've spent a lot of time on this, working on Rust's docs, and the way I see it is that "pointer" is the most generic concept, with "reference" being a more restricted form. So all references are pointers but not all pointers are references. Words are hard.
- ptero 10y agoI agree, Go in the title is irrelevant. Otherwise, it is a decent overview of the notion of pointer, although there are many of such overviews around. My other objection is with using code like * b++ in a text that aims to be crystal clear about a single concept (pointers). That can bring totally irrelevant questions on operator precedence and right / left associations. It would be better to say * b = 201. My 2c.
- umanwizard 10y agoYour asterisk got interpreted as italicization and screwed up your post.
- ptero 10y agoThank you!
- my_ghola 10y agoIf it was pointers in general I would have expected the article to talk about pointer arithmetic, which from other comments in the thread seem to be not possible in Go. What is the use case for pointers then? are parameters passed by value instead of by reference by default?
- pjmlp 10y agoPointer arithmetic is possible in Go via the unsafe package. Here is an example. buff := (*[25][80][2]byte)(unsafe.Pointer(uintptr(addr) + 25))