Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

return a struct

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:

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.

Name: Anonymous 2009-12-26 6:53

>>22
should, might, will, shall, would, may.
One of these words is not like the others!!

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List