Hacker News new | ask | show | jobs
by enneff 5366 days ago
Go doesn't define "lvalues," in the spec, but it does define "addressability." My comment would be more accurate if I had said "Go lets you take the address of any value in memory." (stack or heap)
1 comments

I don't think Go lets you take stack addresses. If you try to do that, it will copy the data structure onto the heap.
The compiler is free to optimize this how it sees fit. Taking the address of a value doesn't necessarily move it to the heap.
I imagine this optimization can only happen once escape analysis is performed. In the general case, address-of moves the data to the heap, or causes it to be stored on the heap in the first place. Correct?
Yes.