-Rp (-Rpe, -Rpt): Large Return Value Type

Group

OPTIMIZATIONS

Scope

Application

Syntax
  -Rp(t|e)
  
  
Arguments

t: Pass large return value by pointer, always with temporary

e: Pass large return value by pointer and temporary elimination

Default
  -Rpe
  
  
Defines

None

Pragmas

None

Description

The Compiler supports this option even though returning a `large' return value may not be as efficient as using an additional pointer. The Compiler introduces an additional parameter for the return value if the return value cannot be passed in registers.

Consider the code in the following listing.

Listing: Example Code


typedef struct { int i[10]; } S;
S F(void);

S s;

void main(void) {

  s = F();

}

In the above case, with -Rpt, the code will appear as in the following listing.

Listing: Pass Large Return Value by Pointer


void main(void) {
  S tmp;

  F(&tmp);

  s = tmp; /* struct copy */

}

The above approach is always correct but not efficient. Instead, pass the destination address directly to the callee. This makes it unnecessary to declare a temporary and a struct copy in the caller (i.e., -Rpe), as shown in the following listing.

Listing: Pass Large Return Value by Pointer and Temporary Elimination


void main(void) {
  F(&s);

}

The above example may produce incorrect results for rare cases (for example, if the F() function returns something overlapping s). Because the Compiler does not detect such rare cases, two options are provided: the -Rpt (always correct, but inefficient), or -Rpe (efficient) options.