mikroC
making it simple...
Function Definition
Function definition consists of its declaration and a function body. The function
body is technically a block – a sequence of local definitions and statements
enclosed within braces
the function, i.e. they have function scope.
The function itself can be defined only within the file scope. This means that func-
tion declarations cannot be nested.
To return the function result, use the
functions of
return
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)
#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 */
}
MikroElektronika: Development tools - Books - Compilers
. All variables declared within function body are local to
{}
type cannot have a parameter – in fact, you can omit the
void
statement altogether if it is the last statement in the function body.
to polar coordinates (r,fi): */
mikroC - C Compiler for Microchip PIC microcontrollers
statement. Statement
return
in
return
page
97
Need help?
Do you have a question about the PIC Microcontrollers PIC12 and is the answer not in the manual?