Ian,

good to know that in general you believe that the returned struct will be
allocated in the caller.
I do think that too, so it's good to know that I'm not thinking too much
outside the box.

Anyway, out of curiosity I will read more about the flavors of compilers
avaliable to use with Go.
To be honest, I thought there was only one compiler avaliable out there for
Go.

Thank you for your time!

Best Regards,
Bruno Novais

2018-03-05 3:25 GMT-03:00 Ian Lance Taylor <i...@golang.org>:

> On Sun, Mar 4, 2018 at 5:57 AM, Bruno Novais <bruno.nov...@synng.com>
> wrote:
> >
> > As you probably noticed by my question, I'm new to this awesome language
> > called Go (coming from C/C++). In C++ I rely a lot on constructor (copy)
> > elision. I think Go doesn't have this concept, but I would like to know
> what
> > happen when I do something like this:
> >
> > func NewStuff() Stuff {
> >   return Sutff{}
> > }
> >
> > What will happen in that case? Will it be store on the stack, and then
> > copied to the caller function? That will probably be inlined, so:
> >
> > func NewStuff() Stuff {
> >   // A lot of pre-processing that won't be inlined.
> >
> >   return Sutff{
> >     Value: var1,
> >     Another: var2,
> >     Etc: var3,
> >   }
> > }
> >
> > The returned value will be copied, or the compiler will optimize and
> change
> > the memory space of the caller function?
>
> Go doesn't provide any special guarantees about this case.  Different
> implementations can do different things.
>
> That said, in general I believe that a returned struct will be
> allocated in the caller and changed directly from the callee.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to