Share via


SH-4 Functions with Variable Argument Lists

If you declare a function to have variable argument lists (varargs), the function passes no arguments in floating-point argument registers. Instead, the SH-3 calling rules apply. For more information about SH-3 rules, see the SH-3 Calling Sequence Specification. This means that a function passes the first four words of the argument block in the general argument registers R4 through R7, and passes all succeeding words in the argument block on the stack in argument order.

If the called function takes the address of any of its arguments, and if the resulting pointer might reference subsequent arguments, that argument and all that follow it must be present in the argument area on the stack. In this case, functions pass no arguments in the floating-point registers, and pass some arguments in registers R4 through R7 in memory instead.

The SH-4 calling sequence provides a varargs implementation to enable a variable argument list.

  • A routine can implement va_list as a C pointer.
  • A routine can implement va_arg() to properly cast and de-reference the va_list. It can then increment the va_list by the size of the given type.
  • A routine can implement va_start() to return the address of the item immediately following the start address.
  • A routine can implement va_end() as a no operation instruction (NOP).

ANSI C rules provide backward compatibility and allow function to be called that have limited or no prototype declarations. In such cases, it is not possible to know on the calling side whether the function uses varargs or not. Therefore, it is necessary to double the mapping of floating-point arguments and pass them using the rules for both circumstances, so that the called function will find the arguments in the expected locations whether it uses varargs or not.

For example, a function call that passes a single floating-point argument would pass the argument in both R4 and FR4. The value in R4 would be used if the called function used varargs to reference its arguments, and FR4 would be used otherwise.

See Also

SH-4 Parameter Passing | Argument Area | Argument Block | Argument Block Mapping | Floating-Point Parameter Example

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.