Re: pointer_to_function?
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Tue, 01 May 2007 12:46:42 +1200
mdh wrote:
Could someone please help me understand p 119 of K&R?int (*)(void*, void*))(numeric ? numcmp:strcmp)
This is a version of qsort that, depending on a command line optional
argument ( -n) sorts lines numerically vs lexicographically.
I think the relevant lines ( well, the ones I am having a problem
with) are as follows.
# include.....
etc
void qsort(void *lineptr[], int left, int right, int (*comp)(void *,
void *)); /** declaration**/
main......{
.....
if(qsort((void**) lineptr, 0, nlines-1, (int (*)(void*, void*))
(numeric ? numcmp:strcmp));
........
}
Is casting the result of (numeric ? numcmp:strcmp) to the required
function pointer type. I assume numcmp uses int* and strcmp uses const
char* for their parameters, hence the need for a cast.
--
Ian Collins.
.
- Follow-Ups:
- Re: pointer_to_function?
- From: mdh
- Re: pointer_to_function?
- From: mdh
- Re: pointer_to_function?
- References:
- pointer_to_function?
- From: mdh
- pointer_to_function?
- Prev by Date: Re: the mystery of <ctrl-d>
- Next by Date: Re: pointer_to_function?
- Previous by thread: pointer_to_function?
- Next by thread: Re: pointer_to_function?
- Index(es):
Relevant Pages
|
Loading