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

Gos lack of pointer arithmetic is one of the design decisions that allows go to be memory safe (http://en.wikipedia.org/wiki/Memory_safe) . If you need need to be naughty with pointers you can use the "unsafe" package. But some environments like GAE or Go playground do not allow this.

Also some of the built-in types like channels and maps are reference types (so they are always passed by reference).



Everything in Go is passed by value, even the "reference types". Those types are called reference types because they hold a reference to some value in memory, exactly like a pointer.

If they were passed by reference, then we would expect this playground snip to print "false": http://play.golang.org/p/r6naknvzng


You are correct, I was not being clear. They are not Go reference types are not reference types in the same way that they are in other languages.

When you pass a slice around are are really passing a small struct around by value (http://golang.org/pkg/reflect/#SliceHeader), and it is that struct that contains the pointer to the data.




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

Search: