Reputation: 263
(int ( * ) (void*, void*))(numeric ? numcmp : strcmp));
numcmp and strcmp are functions with two arguments.
I understand what the conditional operator is doing. That is straightforward.
I can reason that this will evaluate to numcmp(void*, void*) or strcmp(void*, void*), but I don't understand why? Particularly, the: int (*), confuses me.
Upvotes: 1
Views: 58
Reputation: 1158
The expression (int ( * ) (void*, void*))
is just a cast to a function pointer with two void*
arguments returning int
. As for other casts, the syntax resembles a variable declaration without variable name. Then depending on the boolean switch, it is decided which of the functions to cast.
Upvotes: 3