Datasheet

FUNCTION POINTERS
Function Pointers are pointers, i.e. variables, which point to the address of a func-
tion.
// Define a function pointer
int (*pt2Function) (float, char, char);
Note: Thus functions and function pointers with different calling convention (argu-
ment order, arguments type or return type is different) are incompatible with each
other.
Assign an address to a Function Pointer
It's quite easy to assign the address of a function to a function pointer. Simply take
the name of a suitable and known function. Using the address operator & infront of
the function's name is optional.
//Assign an address to the function pointer
int DoIt (float a, char b, char c){ return a+b+c; }
pt2Function = &DoIt; // assignment
Example:
int addC(char x,char y){
return x+y;
}
int subC(char x,char y){
return x-y;
}
int mulC(char x,char y){
return x*y;
}
int divC(char x,char y){
return x/y;
}
160
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5