Section 2: Compiler
77
TI
-
89 / TI
-
92 Plus Sierra C Assembler Reference Manual
Not for Distribution
Beta Version February 2, 2001
When the file containing the above example is compiled, the following warning
will be issued:
warning: incompatible parameter types, func() arg 1
This message is generated because the prototype declaration declares a
function that accepts a short parameter, while the function definition declares a
function that accepts an int parameter. The formal parameter in the function
definition is recognized as an int because the function definition is in the old-style
format; therefore, the integral promotion rules are applied to the short
parameter. To further understand the problem, examine the case in which a
short is pushed as two bytes in the presence of a prototype. A two-byte value
will be pushed onto the stack because a prototype declaration is in scope;
however, a four-byte argument will be expected inside the function that was
defined using the old style. A problem also results if a function that is defined with
a prototype to accept a short is called with an old-style declaration (or no
declaration) in scope.
The above problems can be avoided through exclusive use of prototype
declarations and definitions. The compiler command line flags
-Xf1
,
-Xf2
, and
-Xf3
can be used to verify that appropriate declarations are being utilized. The
-Xf1
flag causes a warning to be issued when a function is called outside the
scope of a function declaration. The
-Xf2
flag causes a warning to be issued
when a function is declared without a prototype. The
-Xf3
flag (the combination
of
-Xf1
and
-Xf2
) causes a warning to be issued if a function is called without a
prototype declaration in scope.
2.11.2.
Passing Argument Values
Several factors determine how an argument value is pushed onto the stack when
a function call is made: the specified command line flags, the type of the
argument, and whether or not a function prototype is in scope. If a function
prototype is not in scope, the integral and floating-point promotion rules will be
applied to the argument types.
The
-XI
flag instructs the compiler to interpret objects of type int as 16 bits
rather than 32 bits (default). Specifying the
-XI
flag, as on the TI-89 / TI-92 Plus,
will cause all integer types (except for type long) to be passed as 16-bit objects
independent of whether a function prototype is in scope. The
-Os#
flags
determine how argument values of different types are passed only in the
presence of a function prototype. In the presence of a prototype, parameters of
type char and short are pushed as two-byte objects when the
-Os2
flag is
specified, and are pushed as four-byte objects when the
-Os4
flag is specified.