Name: Anonymous 2009-12-25 13:14
Hi /prog/
I'm wondering if it's legal to return a struct like the div(3) function does. Example:
By compiling it with gcc I don't get any error nor warning. Besides the produced assembly code is strightforward: it just uses a location in the stack of the calling procedure as storage area for the "retval" variable.
My question is: is it a good way of programming? I feel it's a little weird. Also I know it's better to exploit pointers, but this is not always a choice.
I'm wondering if it's legal to return a struct like the div(3) function does. Example:
typedef struct {
int k;
int j;
} Guybrush;
Guybrush fubar() {
Guybrush retval;
retval.k = 42;
retval.j = 37;
return retval;
}By compiling it with gcc I don't get any error nor warning. Besides the produced assembly code is strightforward: it just uses a location in the stack of the calling procedure as storage area for the "retval" variable.
My question is: is it a good way of programming? I feel it's a little weird. Also I know it's better to exploit pointers, but this is not always a choice.