News for hackers. Stuff that matters.
Re:Understand Go pointers by Aardwolf on Wednesday April 26, 2017 @10:50AM (#14203432)
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."

Re:Understand Go pointers by kazinator on Wednesday April 26, 2017 @10:53AM (#14203454)
> 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.

Re:Understand Go pointers by echlebek on Wednesday April 26, 2017 @11:54AM (#14204085)
They'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_

Re:Understand Go pointers by pjmlp on Wednesday April 26, 2017 @12:00PM (#14204162)
Yes it has, via unsafe package.

Which ANSI C example should I write for you in Go?

Re:Understand Go pointers by echlebek on Wednesday April 26, 2017 @09:39PM (#14208549)
Package 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".

Re:Understand Go pointers by pjmlp on Thursday April 27, 2017 @02:24AM (#14209589)
If package unsafe doesn't "count", anything that C compilers allow beyond what ANSI C specifies don't count as C, thus many of its system programming features just vanish.
Re:Understand Go pointers by echlebek on Thursday April 27, 2017 @10:34AM (#14211740)
I don't see how that relates to Go pointers.