> > > > Do you want the qsort() warnings fixed? AFAICT, all of these
> > > > arise from comparison functions taking pointers to the actual
> > > > object type, but qsort() having a fixed prototype with a fixed
> > > > 4th parameter.
> > > >
> > > > Fixing them is basically a choice of either:
> > > >
> > > > a) changing e.g.:
> > > >
> > > > int compare(foo *a, foo *b)
> > > > {
> > > > return CMP(*a, *b);
> > > > }
> > > > to
> > > > int compare(void *aa, void *bb)
> > > > {
> > > > foo *a = (foo*) aa;
> > > > foo *b = (foo*) bb;
> > > > return CMP(*a, *b);
> > > > }
> > > >
> > > > or:
> > > >
> > > > b) explicitly casting the 4th argument to qsort()
[snip]
The a) option is the correct way to fix this. The compare function
should take void pointers as parameters and cast them to the proper type
inside the function.
Well, in the course of fixing these, I've been reminded (by gcc) that
the arguments to the compare function are "const void *", not "void *".
This turns out to be a bit of a nuisance, as some of the comparison
functions call GRASS library functions, which generally omit the
"const".
There are two specific cases of library functions having the wrong
prototype:
1. src/raster/r.neighbors/cmd/sort_cell.c calls G_is_d_null_value(),
which omits the "const"; here I just discarded the const with an
explicit cast.
2. G_site_[cds]_cmp(), defined in src/libes/gis/sites.c and declared
in src/include/P_site.h. These are specifically intended to be passed
to qsort(), so I fixed the prototype.
However, even more weird than any of this is the comparison function
in do_v_stats(), in src.contrib/SCS/vector/v.report/cmd/do_v_stats.c:
static int cmp (const void *a,const void *b)
{
if(a < b)
return -1;
if(a > b)
return 1;
return 0;
}
Does anyone know if this is meant to be a placeholder for a
not-yet-written comparison function? Or should the qsort()s just be
removed?
One final point: some brain-dead compilers are known to have trouble
with non-trivial uses of the "const" qualifier. If anyone has "const"
trouble, let me know.
--
Glynn Clements <glynn.clements@virgin.net>
----------------------------------------
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo@geog.uni-hannover.de with
subject 'unsubscribe grass5'