Function-types: compatability, and typedefs
Chris Torek
chris at mimsy.UUCP
Sat Sep 2 00:12:45 AEST 1989
>In article <19361 at mimsy.UUCP> I wrote:
>>... the answers FOR THIS PARTICULAR CASE are `yes' and `yes'.
>> int (*)(void *, void *) [qsort compare function]
>> and int (*)(char *, char *) [strcmp]
In article <1996 at munnari.oz.au> ok at cs.mu.oz.au (Richard O'Keefe) writes:
>If you want to sort an array of strings ... **don't** try to pass
>'strcmp' as the fourth argument of qsort(). ... What you need is
> int strptrcmp(char **s1, char **s2)
> { return strcmp(*s1, *s2); }
Oops, quite right. I got tied up in the `do the two function types match'
question and never noticed the fact that qsort is passing pointers to
the objects (here pointers to char *), rather than to that to which the
objects point.
>Did you know that C.A.R.Hoare pointed out in 1962 that Quicksort does
>1.4 times as many comparisons as [the number done by merge sort]?
>He should know: he invented it.
Yes, but everyone likes to analyse Quicksort. :-) That is, I think
the reason it is used so often is, well, because it is used so often.
(Familiarity breeds distemper, or something like that :-/ )
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list