return

Lubos Lunak kde-optimize@mail.kde.org
Mon, 3 Feb 2003 16:24:29 +0100


On Monday 03 of February 2003 17:11, Allan Sandfeld Jensen wrote:
> On Monday 03 February 2003 14:30, David Leimbach wrote:
> > Basically you can have named or unnamed RVO [return value
> > optimization].  I am not sure its really a big deal with this example
> > since you use a built-in, simple type like bool.  If these were objects
> > that used constructors then
> > RVO becomes a lot more important due to the need to copy-construct and
> > default construct  objects.  Neither of those  really happen in your
> > example so to me it seems either way is fine.
>
> <SNIP>
>
> > Sometimes a named return value won't get optimized by some compilers...
> > I don't know if that
> > is the case with gcc or not.
> >
> > The authors also claim that you must define a copy constructor to "turn
> > on" RVO.
>
> gcc has an extention that enables you to write:
>
> Complex operator + (const Complex & a, const Complex & b) return retval
> {
>    retVal.real = a.real + b.real;
>    retVal.imag = a.imag + b.imag;
> }
>
>
> I think it is meant to force this optimization, do you know anything about
> it?

 Yes, it is, but it's not portable. Moreover, the less expensive it is to copy 
the returned object, and the less often this code is executed, the less it 
makes sense to bother with it.

-- 
Lubos Lunak
KDE developer
---------------------------------------------------------------------
SuSE CR, s.r.o.  e-mail: l.lunak@suse.cz , l.lunak@kde.org
Drahobejlova 27  tel: +420 2 9654 2373
190 00 Praha 9   fax: +420 2 9654 2374
Czech Republic   http://www.suse.cz/