Re: pointer_to_function?



mdh wrote:
Could someone please help me understand p 119 of K&R?

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));
........
}

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.
.



Relevant Pages

  • Re: System call not acting as expected
    ... You seem to be expecting the latter behaviour, ... Why are you using commas there ... all sorts of fun problems, like having to sort out terminal escape ... > The result of this line confirms that it is generating exactly the command ...
    (comp.lang.perl.misc)
  • Re: vmware
    ... in my Linux based XP VM and my dedicated Windows desktop. ... depending on what sorts of databases you're dealing with and such. ... Those tech-info databases may be an issue depending on their size, ...
    (Fedora)
  • Re: The Fat Lady Cometh pretty frickin soon, peoplez -- & the Mr Hankys are all eagerly
    ... Tariq's defect assumes into our ... sorts in relation to Yosri's absent register. ... won't identify predictions later. ... depending on the soccer's vat. ...
    (sci.crypt)
  • Re: Ruled text
    ... defining a command to lay out examples in the form of text (perhaps ... containing all sorts of stuff beyond simple paragraphs) set off by ...
    (comp.text.tex)
  • Re: "Measuring" - Dont Be Oral Anal Retentive
    ... you should take a look at Intellicad. ... Price on the full version, again depending on source, ... Same command line, same commands. ...
    (rec.woodworking)

Loading