I'm a little confused... Would it be possible for somebody to identify the order of evaluation and what is actually being declared here, perhaps in terms of pointers and the types we expect to find using these?
A written explanation would also be adequate, all would be awesome. Really any means you feel you can explain fully what this does would be great!
What does this do in C / C++?
int (*f) (float *);
f
is a function pointer. In other words, f
is a pointer to a function that takes in a float*
(pointer to float
) and returns an int
.
Here is an example:
Suppose you have a function like:
int function(float* fltPtr)
{
// ...
return SOME_VALUE;
}
Then, you can use
int (*f) (float *) = &function; // `&` is optional
to make the function pointer f
point to the address of function
. After this, you can use
float flt = 0.5f;
int retVal = f(&flt); /* Call the function pointed to by `f`,
passing in the address of `flt` and
capture the return value of `function` in `retVal` */
to call the function. The above code is equivalent to
float flt = 0.5f;
int retVal = function(&flt); /* Call the function `function`,
passing in the address of `flt` and
capture the return value of `function` in `retVal` */