You copied the Doc URL to your clipboard.

Functions that return multiple values through registers

In C and C++, one way of returning multiple values from a function is to use a structure. Normally, structures are returned on the stack, with all the associated expense this entails.

To reduce memory traffic and reduce code size, the compiler enables multiple values to be returned from a function through the registers. Up to four words can be returned from a function in a struct by qualifying the function with __value_in_regs. For example:

typedef struct s_coord { int x; int y; } coord;
coord reflect(int x1, int y1) __value_in_regs;

__value_in_regs can be used anywhere where multiple values have to be returned from a function. Examples include:

  • Returning multiple values from C and C++ functions.

  • Returning multiple values from embedded assembly language functions.

  • Making supervisor calls.

  • Re-implementing __user_initial_stackheap.

Was this page helpful? Yes No