I also think its undefined. But if I look at K&R example they do something which "looks" like they doing the same undefined action - but I stand corrected. They define two functions which will be used as a parameter to another function:
Code:
int numcmp(char *s1, char *s2){
//do stuff
}
Code:
int strcmp(char *s, char *t){
//do other stuff...
}
The below function is one in which either one of the above 2 functions are pointed to through the use of a function pointer as a fourth argument. Note however that the pointer is void and not of the same type of the functions above - this is so it can accommodate any type of function pointing.
Code:
void qsortcustom(/*arg 1*/, /*arg 2*/, /*arg 3*/, int (*comp)(void *, void *)){
//Do yet more stuff
}
Everything up until now makes sense. However:
Finally, when we call the above function, the code is written like this:
Code:
qsortcustom((void**) lineptr, 0, nlines-1, (int (*)(void*,void*))(numeric ? numcmp : strcmp));
It makes no sense - numcmp and strcmp are functions and now its been cast to a pointer? So my question is, is the above undefined behaviour? Its in the K&R textbook