Path: utzoo!utgpu!watmath!att!pacbell!ames!indri!uakari.primate.wisc.edu!csd4.milw.wisc.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!jima
From: jima@hplsla.HP.COM (Jim Adcock)
Newsgroups: comp.lang.c++
Subject: Re: named return values
Message-ID: <6590226@hplsla.HP.COM>
Date: 8 Aug 89 17:40:53 GMT
References: <1826@cmx.npac.syr.edu>
Organization: HP Lake Stevens, WA
Lines: 36

> 
> X iota()                       // return an X with all p[i] = i
> {
>   X y;                         // create a local X
>   for (int i=0; i     y.set(i, i); 
>   return y;                    // return a copy via X(X&)
> }
> 
> ...
> 
> The best counterargument against this efficiency claim is that a
> *very* smart compiler could translate function iota into something
> like function iota_nrv all by itself. While conceivably true, in
> cases of arbitrarily complicated nesting of arbitrarily complicated
> functions, eliminating all such useless copying would sometimes
> require interprocedural data flow analyses stretching the capabilities
> of any optimizing compiler for any language I know. Thus, relying on
> automated detection seems unrealistic, especially considering that
> this effect can be had in such a simple and natural way with named
> return values.

It doesn't seem to me like it takes a very smart compiler to be able
to figure out that iota uses y as a dummy return variable.  But these
simple cases are precisely where one needs compilers to be a little smarter.
Long and complex functions can afford the cost of the extra copy.  Little
functions can't afford the cost -- but should be easy to optimize.
Let's get C++ compilers that can truly handle the uniquely C++ features
of the language -- initialization, assignment, return values, array 
initialization, registering small structures, efficient this passing, etc.  
These issues are *not* the same as in C compilers -- C++ makes very different 
demands on a compiler's code generating capabilities.

Let's ask C++ compiler writers to design their compilers to meet the state of
the art for the 1990's.  Let's not bollix up the language with a lot more tired
anachronisms like "register."