[LC++]Using the "return value optimization"

Vincent Penquerc'h vincent at qubesoft.com
Mon Aug 13 20:40:04 UTC 2001


> What I would really like it to do, is for return value
> optimization to take the following code:
> 
>   int a=doSomething(parameter);
> 
> and convert it into:
> 
>   int a;
>   doSomething(a, parameter);
> 
> It would seem like this is not possible.

The generated code will probably be quite similar, in
terms of speed. The only problem I foresee is that you
use the address of a variable, so the compiler might be
too afraid to affect it to a hard register, though it
could. But if the reference actually points to something
which is on the stack already (eg a local from the caller)
then it will be in the cache already, and it would mean
only an extra indirection. Unless doSomething is trivial,
this should not be a performance concern.

-- 
Lyrian 




More information about the tuxCPProgramming mailing list