0

I have a function that returns a string, and a structure that wants a string*. Currently I'm doing this https://play.golang.org/p/rFfeONFS33

stupid := a()
y.z = &stupid

What I want (doesn't work) https://play.golang.org/p/Hhh8GP7JJl

z.y = &(a())

Is this because returned values are using the stack? Is there a more elegant way than allocating some other variable with a nonsense name?

Cory Kendall
  • 7,195
  • 8
  • 37
  • 64
  • 4
    Values from functions are not addressable, so yes: You do have to assign the return value to a variable before taking the address. – Volker Dec 13 '16 at 15:34
  • 1
    Also duplicate of [How can I store reference to the result of an operation in Go?](http://stackoverflow.com/questions/34197248/how-can-i-store-reference-to-the-result-of-an-operation-in-go/34197367#34197367); and [How to get the pointer of return value from function call?](http://stackoverflow.com/questions/30744965/how-to-get-the-pointer-of-return-value-from-function-call/30751102#30751102) – icza Dec 13 '16 at 16:06

0 Answers0