User manual
mikroC PRO for dsPIC
MikroElektronika
235
Here is a sample function which depends on side effects rather than return value:
/* function converts Descartes coordinates (x,y) to polar (r,): */
#include <math.h>
void polar(double x, double y, double *r, double *) {
*r = sqrt(x * x + y * y);
* = (x == 0 && y == 0) ? 0 : atan2(y, x);
return; /* this line can be omitted */
}
Functions reentrancy
Functions reentrancy is allowed. Remember that the dsPIC’s and PIC24 has stack and memory limitations which can
varies greatly between MCUs.
Function Calls and Argument Conversions
Function Calls
A function is called with actual arguments placed in the same sequence as their matching formal parameters. Use the
function-call operator ():
function_name(expression_1, ... , expression_n)
Each expression in the function call is an actual argument. Number and types of actual arguments should match those
of formal function parameters. If types do not match, implicit type conversions rules will be applied. Actual arguments
can be of any complexity, but order of their evaluation is not specied.
Upon function call, all formal parameters are created as local objects initialized by the values of actual arguments. Upon
return from a function, a temporary object is created in the place of the call, and it is initialized by the expression of
the return statement. This means that the function call as an operand in complex expression is treated as a function
result.
If the function has no result (type void) or the result is not needed, then the function call can be written as a self-
contained expression.
In C, scalar arguments are always passed to the function by value. The function can modify the values of its formal
parameters, but this has no effect on the actual arguments in the calling routine. A scalar object can be passed by the
address if a formal parameter is declared as a pointer. The pointed object can be accessed by using the indirection
operator * .