From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2002-10-13 12:13:56
Terje Slettebø wrote:
> Is it so that RVO can't
> be applied if there may be a side effect, whereas NRVO can be applied,
> regardless? Having cout's in the copy constructor would certainly constitute
> a side effect.
Exactly. This is the real value the NRVO provides, it allows
optimization which do have observable side effects!
> It is likely that newer compilers will fare better when it comes to NRVO, as
> it gets implemented on more compilers.
GCC has it since v3.1 and it works well. The Intel has it although it's
buggy, but this should be fixed soon. I would personally be interested
to hear about the VC++ 7...
> >Yes. And it's not limited to the Intel C++, as the standard itself
> >requires compilers to behave this way. A compiler is basically allowed to
> >remove temporaries only if it can figure out that this does not have any
> >observable side effects.
> However, that's not the case for NRV, as mentioned, is it? After all, I got
> a varying amount of cout printing, depending on whether or not NRV was used.
> What I'm wondering is, could a value parameter be considered an NRV by the
> compiler, or does it have to be created explicitly in the function?
A by-value-parameter is copied at the callers side of a function, not
within the function itself. That is the reason why a parameter is not a
valid NRV and the optimization cannot be applied.
Thanks for all your testing :)
-- Daniel Frey aixigo AG - financial training, research and technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk