R
Rufus V. Smith
Malcolm said:OK here's an example.
/*
return the maximum value of an stdlib maths function that takes one scalar
as its argument.
*/
double maximum( double (*fptr)(double x) )
{
if( fptr == sin)
return 1.0;
if(fptr == sqrt)
return DBL_MAX;
if(fptr == asin)
return 3.14 * 2.0;
/* add extra for the other function in the maths library */
}
Good One Malcolm!
Almost made me wet my pants.
I've been absent from the newsgroups for a time (unemployment can do that),
but was following this thread with some uneasy interest.
At first I thought, "of course function pointers aren't used only for
callback functions." But after reading and thinking, I decided that
ultimately,
if that function pointer is every actually used it is effectively "calling
back" to
the function it points to.
However, your fine example shows that if we use the function pointers only
as pointers, there is no "calling", hence no "callback" happening.
Which brings me back to one observation, though:
function pointers are NEVER callback functions
They are POINTERS TO callback functions.
let me slip back into my teapot now.
Rufus