Datasheet

Argument Conversions
If a function prototype has not been previously declared, the mikroC PRO for AVR
converts integral arguments to a function call according to the integral widening
(expansion) rules described in Standard Conversions. If a function prototype is in
scope, the mikroC PRO for AVR converts the passed argument to the type of the
declared parameter according to the same conversion rules as in assignment state-
ments.
If a prototype is present, the number of arguments must match. The types need to
be compatible only to the extent that an assignment can legally convert them. The
user can always use an explicit cast to convert an argument to a type that is accept-
able to a function prototype.
Note: If the function prototype does not match the actual function definition, the
mikroC PRO for AVR will detect this if and only if that definition is in the same com-
pilation unit as the prototype. If you create a library of routines with the correspon-
ding header file of prototypes, consider including that header file when you compile
the library, so that any discrepancies between the prototypes and actual definitions
will be detected.
The compiler is also able to force arguments to change their type to a proper one.
Consider the following code:
int limit = 32;
char ch = 'A';
long res;
// prototype
extern long func(long par1, long par2);
main() {
...
res = func(limit, ch); // function call
}
Since the program has the function prototype for func, it converts limit and ch to
long, using the standard rules of assignment, before it places them on the stack for
the call to func.
Without the function prototype, limit and ch would be placed on the stack as an
integer and a character, respectively; in that case, the stack passed to func will not
match size or content that
func expects, which can cause problems.
191
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5