svn commit: r247014 - head/lib/libc/stdlib
Giorgos Keramidas
keramida at FreeBSD.org
Wed Feb 20 09:49:44 UTC 2013
On 2013-02-20 09:32, David Chisnall <theraven at FreeBSD.org> wrote:
> On 20 Feb 2013, at 08:25, mdf at FreeBSD.org wrote:
> > These should be declared const int *. And the cast shouldn't be
> > needed in C, since void * can be assigned to any other pointer type.
>
> In fact, the entire function body can be replaced with:
>
> return (*(int*)p1 - *(int*)p2);
>
> qsort doesn't require that you return -1, 0, or 1, it requires you return <0, 0, or >0.
That's true. Since we are trying to document the interface, I'd prefer
if we don't compress the comparison too much. Would something like this
be ok too?
int
int_compare(const void *p1, const void *p2)
{
const int *left = p1;
const int *right = p2;
return (*left - *right);
}
More information about the svn-src-all
mailing list