Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!bs From: bs@alice.UUCP (Bjarne Stroustrup) Newsgroups: comp.std.c++ Subject: Re: Unnecessary copying of returned object Summary: can be avoided Message-ID: <11266@alice.UUCP> Date: 1 Sep 90 13:09:19 GMT References: <1990Aug31.234937.29938@athena.mit.edu> <1990Aug31.235606.166@athena.mit.edu> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 19 Antony Hodgson @ Massachusetts Institute of Technology writes > Consider the following: > > 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 it could. The technique is described in the annotated C++ reference manual in section 12.1.1c. I believe the technique is used in the Zortech compiler (existence proof).