4 ms·
Looks the same as C pointers. Maybe the title is more clear if it would be: "Understand pointers, using Go". Then for a C programmer it's clear from the title t
by Aardwolf 10y ago
Looks the same as C pointers. Maybe the title is more clear if it would be: "Understand pointers, using Go". Then for a C programmer it's clear from the title that "pointers" is the same concept, and Go doesn't have a different type of "Go pointers".
Or instead of starting with:
"This post is for programmers coming to Go who are unfamiliar with the idea of pointers or a pointer type in Go."
It could start with:
"This post is for programmers coming to Go from a language without pointers or a pointer type."
- kazinator 10y ago> Then for a C programmer Maybe that's not the target audience? Tutorials targetted at C newbies have been about "C pointers" for eons; why would Go tutorials refer to a different programming language? What that program is doing would not be well-defined in C; you cannot increment a pointer from the address of one local variable to point to another, without leaving behind the ISO C standard dialect. I haven't seen any compiler-specific document which "blesses" the practice. If that is well-defined in Go, that would be an excellent reason why the article really is specifically about Go pointers and not C pointers.
- echlebek 10y agoThey're not the same. Go doesn't have pointer arithmetic, and Go functions can safely return pointers to values that aren't created via new(). https://play.golang.org/p/m3OdaXH98_ https://play.golang.org/p/m3OdaXH98_
- pjmlp 10y agoYes it has, via unsafe package. Which ANSI C example should I write for you in Go?
- echlebek 10y agoPackage unsafe is in the spec, but converting unsafe.Pointer to uintptr (which is how I'm supposing you'd do your pointer arithmetic) is implementation-defined. This means I could create a perfectly legal implementation of Go where such things result in complete nonsense. I don't think package unsafe "counts".