I am using qsort library function to sort an array of structure elements, while searching on the Internet I found a resource: INFO: Sorting Structures with the C qsort() Function @ support.microsoft.
I understand that qsort function requires to be typecast by generic pointers.
However I am not able to get this line:
typedef int (*compfn) (const void*, const void*);
Which has been declared, and its subsequent call:
qsort((void *) &array, // Beginning address of array
10, // Number of elements in array
sizeof(struct animal), // Size of each element
(compfn)compare // Pointer to compare function
);
- How is
typedef
behaving, I mean what exactly have we typedeffedint (*compfn)
orint (compfn)
? - If the former, then shouldn't the call be
(*compfn)
?