Section 2: Compiler
75
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
An in-scope prototype function declaration not only establishes the function
return type, but also enables verification that the function is called with the
correct number of arguments and that the type of each argument is compatible
with its corresponding formal parameter. The type checking and conversions that
are performed are identical to those performed when assigning a value using the
assignment operator ( = ). For example, if a function that is defined with a
parameter of type double is called with an argument of type int, the argument is
automatically converted to a value of type double before being pushed onto the
stack; an explicit cast operator is unnecessary. Additional arguments permitted
by the ellipsis notation (, . . .) are handled as if they were arguments to a function
declared without a prototype. When declared with the ellipsis notation, type
checking and automatic type conversions cannot be performed; instead, the
ANSI C integral and floating-point promotion rules are applied to the arguments.
The following is an example of a prototype function definition:
double f1( short a, int b, double c )
{
/* function body */
}
The function f1 is defined to accept three arguments and return a value of type
double. The formal parameter type declarations int a, short b, and double c
declare how the parameters will be used inside the function. The Sierra C
compiler specifies how the parameters are pushed onto the stack at the function
call site. If a prototype declaration is in scope, an argument of type short may be
promoted to an int before being pushed onto the stack. The rules for determining
how an argument is pushed onto the stack in the presence of a prototype is
determined by specific command line flags. Table 2.4 (section 2.11.2 Passing
Argument Values) summarizes how arguments of different types are pushed
onto the stack with and without a prototype in scope.
2.11.1.2. Old-Style
Declarations
An old-style function declaration is a declaration that provides only the type of the
return value. Information on the types and number of arguments is not
established. The following is an example of an old-style (nonprototype) function
declaration:
int f5();
The function f5 is declared to return a value of type int; no information about the
number and types of arguments is specified. This declaration could be deleted
from the program without any effect, since the default function return type is int.