Topic: no subject
Author: Norman Goldstein <normvcr@istar.ca>
Date: 2000/07/22 Raw View
This response did not appear and was not acknowledged by the std.c++
newsgroup.
This is in response to article #4 in the thread. Might you put it in
for me?
Also, my original posting, which started the thread, is no longer in
the newsgroujp.
Any idea why I might be having these problems with this newsgroup?
Thanks for any help!
===============================================================
It seems to me that the GNU C++ solution, below, is exactly
what I am looking for. More comments follow ...
Christopher Eltschka wrote:
> Andre Poenitz wrote:
> >
> > Marco Manfredini (marco@no-taris-spam.de) wrote:
> > > In fact, GNU C++ already has such an extension to the language,
which
> > > doesn't need a new assignment operator. In an extra clause, you
can define
> > > the name of a return value:
> > >
> > > Foo f(void) return r; // yes with ';'
> > > {
> > > r.var1=0;
> > > }
> >
> > I always found this annoying.
> >
I assume that the variable "r" is implicitly a reference to type "Foo".
What is it that you find annoying about this notation/approach?
>
> > I believe the same effect could be reached if there was a special
> > variable name that could be handled with extra care by the
optimizer.
> >
I don't like the idea of depending on the optimizer, or compiler
cleverness, when
one's exact
intent can be achieved so clearly and succinctly.
>
> > Let's say, the special variable name is 'result', so one would write
> >
> > Foo f(void)
> > {
> > Foo result;
> > result.var1=0;
> > return result;
> > }
> >
> > *as usual*. The compiler could check, whether result and the return
> > type of f are the same, whether result is returned and whether
nothing
> > else is return. If any of these tests fail, it's business as usual.
> > Otherwise, the variable could be removed by the optimizer.
> >
This doesn't work if the caller of f() is assigning the result to an
object
derived
from Foo. For example, the virtual function mechanism is bypassed.
>
> > This way one would get the best of both worlds: No extension to the
> > languange _and_ optimal code.
>
> Indeed, the standard chose an even better option:
> The compiler may optimize the above as stated _independent_
> from the variable name. The rational is easy: If the compiler
> can do the required checks if the variable is called result,
> it can do them if it's called foo either.
> This mechanism is called "named return value optimisation" (NRVO)
> (note that g++'s extension was given the same name, since
> it was invented before the standard used the name - a classic
> naming conflict ;-))
>
> I don't know which compilers implement the std::NRVO
> (maybe even g++ supports std::NRVO besides gcc::NRVO now).
>
Would you please give a reference to std::NRVO ? I checked the C++
language standard, and there is no mention of it, there.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]