I wouldn't label the use of function pointers in terms of
optimization or fast calls. Instead I style my understanding
of function pointers in the terms of pointer variables. In C a function,
by itself, is not a variable. Pointers to functions are variables and
can be used in assignments, arrays, passed to functions, etc.
Examples:
typedef int (*FuncPointer)(void);
int foo(void)
{
return 6;
};
int bar(void)
{
return 10;
};
You cannot do this:
foo = bar;
But you can do this:
FuncPointer p1,p2;
p1 = foo;
p2 = bar;
p1 = p2;
FuncPointer parray[] = {foo,bar};
int d = parray[0]();
int Afunction(int i, FuncPointer p){return i*p();};
and the call:
int d = Afunction(2,foo);
#include <stdio.h>
typedef int (*FuncPointer)(void);
int foo(void)
{
return 6;
};
int bar(void)
{
return 10;
};
int Afunction(int i, FuncPointer p){return i*p();};
int main(void)
{
FuncPointer p1,p2;
FuncPointer parray[] = {foo,bar};
int d;
p1 = foo;
p2 = bar;
printf("p2 returns %d\n",p2());
d = parray[0]();
printf("d = %d\n",d);
d = Afunction(2,foo);
printf("d = %d\n",d);
return 0;
}
hope you can understand this properly