Function pointers are a complex and very powerful feature of C. They allow you to pass one function as an argument to another function. We will not describe function pointers here, except for an illustration of how a function can be passed to a CCATSL function, and how to work-out from the declaration of the CCATSL function how your function must be declared:
|
double f(double x) {
return x*x-1.0;
}
int main(void) {
double ans, err;
/* integrate f over 0, 1 using 256 sub-intervals */
ans = RombergCL(f, 0.0, 1.0, &err, 8);
}
|
RombergCL is declared as:
|
double RombergCL(double a, double b, int n, double (*f)(double x),
double *err);
|
|
void (*fp)(int, double, const char*) |
int, a double and
a char*, it returns nothing (it returns a void), and
promises not to modify the memory pointed to by the final argument
(the const qualifier). Pointers are described in detail
here.