Kunseok
Kunseok

Reputation: 263

referencing functions with pointers

(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

Answers (1)

nucleon
nucleon

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

Related Questions