Nov 28, 2009, 1:02:48 PM11/28/09
> a:=makeFoo(parameters); // creates Foo on stack
> b:=&makeFoo(parameters); // was supposed to create Foo on heap, but
> it's not a valid expression.
From my limited understanding, the reason this isn't a valid
expression is that function results are usually in a CPU register, so
they have no memory address.
If you wanted makeFoo to allocate your Foo on the heap, you would have
to use 'new' inside your function, then return the pointer.
If makeFoo allocated Foo on the stack, then returned it, it has to
return it as a copy anyway, because the stack pointer would roll back
after the return, and Foo's original stack-memory location could get
used for something else very shortly.
This is how I remember it working in C anyway... Go could be
different, and C was so long ago I could also just be wrong about
these details. :)