Structure return
Paulo Flabiano Smorigo
pfsmorigo@gmail.com
Fri Nov 6 18:46:00 GMT 2009
Hi everyone,
Is it possible to return a structure as the function return?
I made a program to test if it's possible and worked, but now I have a
few doubts:
- It's secure to use this procedure?
- It's a true structure return or something else?
- The ansi c standard allow this or it's a "plus" of gcc?
The program that I made to test:
#include <stdio.h>
typedef struct myStruct_
{
int a;
char b, c;
} myStruct;
myStruct getMyStruct()
{
myStruct sample;
printf("sample: %x\n", (unsigned int)&sample);
sample.a = 5;
sample.b = 6;
sample.c = 7;
return sample;
}
int main()
{
myStruct myStr;
printf("before: %x\n", (unsigned int)&myStr);
myStr = getMyStruct();
printf("after: %x\n", (unsigned int)&myStr);
printf("a: %d\n", myStr.a);
return 0;
}
Thanks in advance,
Paulo Flabiano Smorigo
More information about the Gcc-help
mailing list