Structure return

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux