Bug#357051: libc.info s9.4 qsort example is wrong
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.
ttfn/rjk
Reply to: