Knowledge Base Article
Answer: Function pointer: A function pointer is a variable that stores the address of a function that can later be called through that function pointer. By changing the value of a pointer we can call different functions in the same project. For this, the prototype of function pointer and function which is called using the pointer should be the same.
A function pointer can be declared as:
(*) (type of function arguments)
For example: void (*fptr) (int); Here, fptr is a pointer to a function taking one argument, an integer, and that returns void. To call the function pointed to by a function pointer, you treat the function pointer as though it were the name of the function you wish to call. #include void my_func1(int x) { //print the function void my_func2(int y) { //print the function } void main() { void (*fptr) (int); fptr=&my_func1; //& is optional (*fptr)(2); //calling the function my_func1 through pointer fptr=&my_func2; //& is optional (*fptr)(6); //calling the function my_func2 through pointer } Function pointer is the property of C. So all the microcontrollers, such as PSoC 1, PSoC 3, and PSoC 5 will support it.
For example:
void (*fptr) (int);
Here, fptr is a pointer to a function taking one argument, an integer, and that returns void. To call the function pointed to by a function pointer, you treat the function pointer as though it were the name of the function you wish to call.
#include void my_func1(int x) { //print the function
void my_func2(int y) { //print the function }
void main() {
fptr=&my_func1; //& is optional (*fptr)(2); //calling the function my_func1 through pointer
fptr=&my_func2; //& is optional (*fptr)(6); //calling the function my_func2 through pointer
Function pointer is the property of C. So all the microcontrollers, such as PSoC 1, PSoC 3, and PSoC 5 will support it.