Go to main content
Oracle® Developer Studio 12.6: C User's Guide

Exit Print View

Updated: July 2017

9.3 Argument-Passing Mechanism

This section describes how arguments are passed in ISO C.

  • All arguments to C functions are passed by value.

  • Actual arguments are passed in the reverse order from which they are declared in a function declaration.

  • Actual arguments that are expressions are evaluated before the function reference. The result of the expression is then placed in a register or pushed onto the stack.

G.3.1 32-Bit SPARC

Functions return integer results in register %o0, float results in register %f0, and double results in registers %f0 and %f1.

long long integers are passed in registers with the higher word order in %oN, and the lower order word in %o(N+1). In-register results are returned in %o0 and %o1, with similar ordering.

All arguments, except double and long double, are passed as 4-byte values. A double is passed as an 8-byte value. The first six 4-byte values (double counts as 8) are passed in registers %o0 through %o5. The rest are passed onto the stack. Structures are passed by making a copy of the structure and passing a pointer to the copy. A long double is passed in the same manner as a structure.

Registers described are as seen by the caller.

G.3.2 64-Bit SPARC

All integral arguments are passed as 8-byte values.

Floating-point arguments are passed in floating-point registers when possible.

G.3.3 x86/x64

Intel 386 psABI and AMD64 psABI are observed.

Functions return results in the following registers:

Table 120  Registers Used by x86 Functions to Return Types (-m32)
Type Returned
long long
%edx and %eax
float, double, and long double
float _Complex
%eax for the real part and %edx for the imaginary part
double _Complex and long double _Complex
The same as a struct that contains two elements of the corresponding floating-point type.

All arguments except structs, unions, long longs, doubles and long doubles are passed as four-byte values; a long long is passed as an 8-byte value, a double is passed as an 8-byte value, and a long double is passed as a 12-byte value.

structs and unions are copied onto the stack. The size is rounded up to a multiple of four bytes. Functions returning structs and unions are passed a hidden first argument, pointing to the location into which the returned struct or union is stored.

Upon return from a function, the caller is responsible for popping arguments from the stack except for the extra argument for struct and union returns that is popped by the called function.