Thu Dec 15 09:49:21 EST 2011

Composite return values in C

This is something which I never use because I thought it was not
possible, but returning composite values is not a problem in C.  What
I wonder is how the ABI handles this.

  struct foo {
      int a;
      int b;
      int c;

  struct foo make_foo(void) {
      struct foo foo = {};
      return foo;

As mentioned in [1], see the -fpcc-struct-return and
-freg-struct-return options in [2].  It seems that this is in essence
not a problem.

[1] http://stackoverflow.com/questions/161788/are-there-any-downsides-to-passing-structs-by-value-in-c-rather-than-passing-a
[2] http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html