Also, how 'ToPointer(v)' is better than writing just plain '&v'?
I’ve personally never needed it outside of tests.
The stack is an implementation detail that's purely about optimization.
(I don't know for sure whether it's safe to thing like this in Go. It's safe to think like this in most Lisps, OCaml or Haskell.)
I also found code that demonstrates stack variables being moved despite a pointer to them, but it's version dependent so I can't test it.
When a variable is moved, then obviously pointers to it need to be updated, but that's not an intractable problem.
Looking further, Go doesn't even provide an API for pinning objects right now[1]. You have to do weird workarounds to allocate static objects, or write code that assumes nothing on the heap moves and will explode if that ever changes.
Some simple examples:
Although a quick grep shows I mainly use these when writing tests.I hope they allow type aliases on generics soon.
in package a:
in package b: I found a need for this recently when updating a bunch of code in a common package I have to use generics. The above type alias would have meant I didn't have to update any code that uses that common package - the transition to generics "under the hood" would have been seamless. Oh well, nothing sed can't handle.