Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Mac OS Runtime Architectures /
Chapter 5 - CFM-68K Runtime Conventions


Routine Calling Conventions

This section details the process of passing parameters to a routine in the CFM-68K runtime environment.

Note
These parameter passing conventions are part of Apple's standard for procedural interfaces. Object-oriented languages may use different rules for their own method calls. For example, the conventions for C++ virtual function calls may be different from those for C functions.
A routine can have a fixed or variable number of arguments. In an ANSI-style C syntax definition, a routine with a variable number of arguments typically appears with ellipsis points (...) at the end of its input parameter list.

A variable-argument routine may have several required (that is, fixed) parameters preceding the variable parameter portion. For example, the function definition

mooColor(number,[color1. . .])
gives no restriction on the number of color arguments, but you must always precede them with a number argument. Therefore, number is a fixed parameter.

The calling routine passes parameters by pushing their values onto the stack, and the stack grows downward (towards lower addresses) with each push. The rightmost parameter is the first pushed onto the stack, with the others following from right to left. For example, given the code

cow = mooFunc(moo1, moo2, moo3);
the calling routine first pushes the value of moo3 onto the stack, followed by moo2 and then moo1.

The return address of the routine is the last item pushed onto the stack.

Note
The order of passing parameters onto the stack in CFM-68K is identical to that for the classic 68K C calling convention. For information about the 68K stack structure, see "Classic 68K Stack Structure and Calling Conventions," beginning on page 11-4.

Subtopics
Parameter Deallocation
Stack Alignment
Fixed-Argument Passing Conventions
Variable-Argument Passing Conventions
Function Value Return
Stack Frames, A6, and Reserved Frame Slots
Register Preservation

Previous Book Contents Book Index Next

© Apple Computer, Inc.
11 MARCH 1997