This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Passing a reference to a value returned by a function
- From: Mihnea Balta <dark_lkml at mymail dot ro>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 11 Mar 2003 17:56:34 +0200
- Subject: Passing a reference to a value returned by a function
Hi.
I have this piece of code (excuse the long function names, it's example code
:) ):
#include <stdio.h>
struct type_t{
int a, b, c;
};
type_t function_returning_struct(){
type_t a;
a.a = 1;
return a;
}
int function_taking_reference(type_t& a){
if(a.a == 1)
return 1;
else
return 0;
}
int main(){
printf("%d\n", function_taking_reference(function_returning_struct()));
return 1;
}
I'm trying to port code written like this from visualc to gcc. I suppose that
visualc compiles the above piece of code because it creates a temporary
type_t that holds the return of function_returning_struct(), and passes a
reference to that to function_taking_reference(). However, gcc 3.2.2 won't
compile that kind of code.
Is there any way to make gcc work with such code? I'm asking because it's in a
lot of places, and adding a temp var by hand to all the places where this
stuff occurs would be a pain.
Thanks.