Tuesday, 6 August 2013

Pointer to functions in C

Pointer to functions in C

Is this syntax correct?
cmp is a pointer to a function. Everything in my program works ok, BUT :
look ! I didn't use * when I declared cmp in the function. Why does my
code work?
When I declare it with int (*cmp) everything also works great.
What is going on here ??
RangeTreeP createNewRangeTree(Element participateWorkers[], int arrsize,
int cmp(ConstElement, ConstElement))
Shouldn't it be:
RangeTreeP createNewRangeTree(Element participateWorkers[], int arrsize,
int (*cmp)(ConstElement, ConstElement))
?
The call to this createNewRangeTree function is :
createNewRangeTree(tempArr, NUM_PAR, &teacherCmpSalary)
and teacherCmpSalary is a regular function that looks like this :
int teacherCmpSalary(ConstElement c1, ConstElement c2)

No comments:

Post a Comment