On 8 Nov 2004 11:19:05 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote:
Rolf Wester <ro*********@ilt.fraunhofer.de> scribbled the following:
I want to pass a C-function as a function parameter but I don't know
how to that correctly. In the example below how would I have to declare
the function argument in the my_sort function definition?
<snip> void my_sqsort(double *a, int n, int (*comp_func)(double *a1, double *a2))
Or you can omit the parameter names, if you prefer:
void my_sqsort (double *a, int n,
int (*comp_func)(double *, double *) )
Since the parameter names aren't used/usable within this function
(only the function to which this parameter points) this is arguably
clearer; however it differs from the target function definition (even)
if that is (also) in prototype format which you may dislike.
Or you can omit the parameter description entirely:
void my_sqsort (double *a, int n, int (*comp_func) () )
which is less safe as it doesn't (at least isn't required to) check
compatibility of calling signatures, but more powerful as it allows
you to pass functions (pointers) with differing signatures -- and you
must take responsibility for ensuring that you call them correctly.
- David.Thompson1 at worldnet.att.net