🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #474

Re: Unnecessary copying of returned object

#474
From: Andrew Koenig
Date: Sat, 01 Sep 1990 13:21
27 lines
1319 bytes
In article <1990Aug31.235606.166@athena.mit.edu>, ahodgson@hstbme.mit.edu (Antony Hodgson) writes:

> 	Vector Vector::operator + ( Vector & A )
> 		{
> 			Vector temp;
> 			// for all valid i, temp[i] = (*this)[i] + A[i]
> 			return temp;  // copy of temp made here
> 		} // temp deallocated here

> Could an intelligent compiler bypass this copying without the help of
> any new syntax?

Yes.

Moreover, I hear that at least one commercially available C++
implementation already does this.

One fairly easy to express such an optimization would be to say that
`if every return statement in a function returns the same local
variable, and that local variable has the same type as the
function's return value, then the compiler should alias the
local variable to the return value.'

The language definition permits this optimization.
-- 
				--Andrew Koenig
				  ark@europa.att.com
Technical Details
Message-ID: <11267@alice.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!ark
References: <1990Aug31.234937.29938@athena.mit.edu> <1990Aug31.235606.166@athena.mit.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!ark
From: ark@alice.UUCP (Andrew Koenig)
Newsgroups: comp.std.c++
Subject: Re: Unnecessary copying of returned object
Message-ID: <11267@alice.UUCP>
Date: 1 Sep 90 13:21:56 GMT
References: <1990Aug31.234937.29938@athena.mit.edu> <1990Aug31.235606.166@athena.mit.edu>
Organization: AT&T Bell Laboratories, Liberty Corner NJ
Lines: 27