Article View: comp.std.c++
Article #2162Re: Why not adopt gcc's "return" optimization?
From: Steve Clamage
Date: Tue, 10 Oct 1995 20:42
Date: Tue, 10 Oct 1995 20:42
35 lines
1834 bytes
1834 bytes
In article I0J@netcom.com, arnstein@netcom.com (David Arnstein) writes:
>Gcc's "return" extension to c++ looks like this:
>
> Integer operator+ (const Integer& x, const Integer& y) return r
> {
> add(x, y, r);
> }
>
>The "return r" clause in the first line prevents a copy of an Integer
>object on function return.
>
>Has the committee considered this extension? It seems so sensible
>that I wonder why it was never adopted.
It seems to me that this extension does not involve any semantic change,
but provides only an explicit hint for an optimization. I don't see that
this hint tells the compiler any more than it could figure out for itself
in the absence of the extension. In many cases compilers can and do
optimize away extra copies of a returned value.
Could you supply an example where the extension necessarily allows the
compiler to generate better code? That is, without the extension you
would have to write the code slightly differently. I'd like to see an
example where the C++ semantic rules require less efficient code than
that allowed by the extension.
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<45ejq1$ojo@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<arnsteinDG8zHt.I0J@netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Why not adopt gcc's "return" optimization? Date: 10 Oct 1995 20:42:31 GMT Organization: Sun Microsystems Inc. Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <45ejq1$ojo@engnews2.Eng.Sun.COM> References: <arnsteinDG8zHt.I0J@netcom.com> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: physics2.berkeley.edu