This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
change in the way a struct is returned from gcc 2.95 gcc 3.3.1
- From: Ravi Krishna <ravikrish at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 21 Sep 2005 15:45:46 +0530
- Subject: change in the way a struct is returned from gcc 2.95 gcc 3.3.1
- Reply-to: ravikrish at gmail dot com
In short if gcc has to return a struct, it first puts it in the stack
of the callee and then copies it
to the stack of the caller.
I have described the problem at the following blog
http://blog.360.yahoo.com/blog-Soi.8NUyaKJGQJEysjIbGQ--?p=2
I thought it was a bug .. but that may not ne true ..
someone one told me that this was done to support overloaded copy
constructor's in C++,
I am curious to know why this was done. In particular why following
transformation was not done ie given
main ()
{ class X x;
x = foo();
}
X foo () {
return X(2,3);
}
now the gcc may make x = foo(); => foo( &x);
so foo gets addr of x in main's stack ..
and foo becomes
void foo( X * x) {
return x->copy_constructor (2,3 )
}
in this case no copy from foo's stack to main's stack will be needed ..
Thanks and Regards,
Ravi Krishna