Datasheet
The function itself can be defined only within the file scope, which means that func-
tion declarations cannot be nested.
To return the function result, use the return statement. The statement return in func-
tions of the void type cannot have a parameter – in fact, the return statement can
be omitted altogether if it is the last statement in the function body.
Here is a sample function definition:
/
* function max returns greater one of its 2 arguments: */
int max(int x, int y) {
return (x>=y) ? x : y;
}
Here is a sample function which depends on side effects rather than return value:
/* function converts Descartes coordinates (x,y) to polar (r,fi): */
#include <math.h>
void polar(double x, double y, double *r, double *fi) {
*r = sqrt(x * x + y * y);
*fi = (x == 0 && y == 0) ? 0 : atan2(y, x);
return; /* this line can be omitted */
}
Functions reentrancy
Functions reentrancy is allowed. Remember that the AVR has stack and memory
limitations which can varies greatly between MCUs.
189
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5