[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#357051: libc.info s9.4 qsort example is wrong



Version: 2.16-0experimental1

On 2006-03-15 13:31, Richard Kettlewell wrote:
> Package: glibc-doc
> Version: 2.3.2.ds1-22
> 
> The example for qsort has, among other things:
> 
>      int
>      critter_cmp (const struct critter *c1, const struct critter *c2)
>      {
>        return strcmp (c1->name, c2->name);
>      }
> 
>      /* ... */
> 
>        result = bsearch (&target, muppets, count, sizeof (struct critter),
>                          critter_cmp);
> 
>      /* ... */
> 
>        qsort (muppets, count, sizeof (struct critter), critter_cmp);
> 
> This is incorrect.  The comparison function must be declared as
> 
>   int critter_cmp (const void *c1, const void *c2)
> 
> and should use casts to convert to the proper type.

This has been fixed in version 2.16, in upstream commit e39745ffa030.
Closing the bug.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net


Reply to: