This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Named Return Value Extension Proposal
- To: egcs at egcs dot cygnus dot com
- Subject: Re: Named Return Value Extension Proposal
- From: "E. Robert Tisdale" <edwin at netwood dot net>
- Date: Tue, 23 Mar 1999 08:57:25 -0800
- References: <199903231442.GAA13756@kankakee.wrs.com>
Mike Stump wrote:
> > Date: Mon, 22 Mar 1999 20:04:10 -0800
> > From: "E. Robert Tisdale" <edwin@netwood.net>
> > To: egcs@egcs.cygnus.com
>
> > Mike Stump wrote:
>
> > > > From: "E. Robert Tisdale" <edwin@netwood.net>
> > >
> > > > It solves the problem that the egcs compiler has with function X f1(int)
> > > > but the function definition is entirely incompatible with ANSI C++
> > >
> > > Yes.
> > >
> > > > and it cannot solve the problem that the compiler has with function
> > > > X g0(X).
> > >
> > > Why not?
> > >
> > > X g0(X x) return x(x) {
> > > cerr << "The copy constructor may be called for g0(X)." << endl;
> > > return x;
> > > }
> > >
> > > If this doesn't scope this way now,
> > > I don't see it as a problem to fix it so that it does,
> > > and so that the semantics of it just work the way you expect.
>
> > Not quite. The function prototype is X g0(X); which means that the
> > compiler creates a temporary for argument X when X g0(X) is called
> > then the copy constructor is called to initialize the return value
> > for g0(X) before entering the body of the function.
>
> Maybe I am just being slow...
>
> And does your new extension fix this problem? If it does,
> how can it, and can't the existing extension fix it the same way?
> If not, why not? If so, I still claim they are identical
> and that your listing of g0 was unfair and misleading.
I don't know why you are confused.
Perhaps you just haven't noticed that your version
> X g0(X x) return x(x) {
> cerr << "The copy constructor may be called for g0(X)." << endl;
> return x;
> }
was not defined to be inline.
Your version of X g0(X) may be a library function
and the definition may not be visible to the compiler.
If so, the compiler has only the function prototype X g0(X)
for your version which doesn't tell it that the argument
is simply a reference to the return value
but the prototype X g0(X return) for my version
would include this information
so that the calling program can call a constructor
to initialize the return value instead of the function argument.
The calling program does not actually pass an argument
to my version of X g0(X return) because the "argument"
is actually just a reference to the return value.
Hope this helps, E. Robert Tisdale <edwin@netwood.net>