74
Section 2: Compiler
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
The amount of stack space used by each function argument is determined by the
type of the argument and whether the function is declared with a function
prototype. Structure arguments are pushed onto the stack and take as much
stack space as necessary to fit the entire structure. If necessary, the stack space
allocated to a structure argument is rounded up to a multiple of four bytes.
2.11.1.
Declarations and Definitions
A function
declaration declares a variable to be a function and specifies the type
of value it returns. A prototype function declaration also establishes the number
of function arguments and the types of those arguments. A function declaration
does not cause memory to be allocated or code to be generated. A function
definition causes memory to be allocated and code to be generated; it also
serves as a function declaration.
2.11.1.1. Function
Prototypes
A function prototype is a function declaration or definition that specifies both the
number of arguments and the argument types. Function prototypes prevent
errors caused by passing the wrong argument type or wrong number of
arguments to a called function.
The following are examples of prototype function declarations:
double f1( short x, int y, double z );
double f2( short, int, double );
double f3( short, int, double, ... );
double f4( void );
The functions f1, f2, f3, and f4 are declared to return a value of type double. The
first two functions are declared to accept exactly three arguments: a short, an
int, and a double, respectively. Except for the function names, the first two
function declarations are identical. The formal parameters x, y, and z in function
f1 are optional and are used for documentation purposes only. The scope of
these optional parameter names extends only to the end of the declaration; the
names do not have to match the formal parameter names in the actual function
definition. Function f3 is declared to accept three or more arguments. The ellipsis
notation (, . . .) informs the compiler that zero or more additional arguments of
unknown type will be passed to the function. In the body of the function definition,
the macros va_start( ) and va_arg( ) defined in the include file tiams.h should
be used to access the additional argument values. Function f4 is declared to
accept no arguments; calling f4 with any arguments will result in an error.