change in the way a struct is returned from gcc 2.95 gcc 3.3.1

Ravi Krishna ravikrish@gmail.com
Wed Sep 21 10:16:00 GMT 2005


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



More information about the Gcc-help mailing list