This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Fix warnings in manual/examples/search.c
- From: Paul Eggert <eggert at cs dot ucla dot edu>
- To: Andreas Jaeger <aj at suse dot de>
- Cc: libc-alpha at sources dot redhat dot com
- Date: Wed, 16 May 2012 10:37:17 -0700
- Subject: Re: Fix warnings in manual/examples/search.c
- References: <hoaa18gygk.fsf@byrd.suse.de>
On 05/16/2012 04:24 AM, Andreas Jaeger wrote:
> -critter_cmp (const struct critter *c1, const struct critter *c2)
> +critter_cmp (const void *v1, const void *v2)
> {
> + struct critter *c1 = (struct critter *)v1;
> + struct critter *c2 = (struct critter *)v2;
> +
> return strcmp (c1->name, c2->name);
Please redo it so that no casts are needed, as pointer casts
are big hammers that shouldn't be used unless necessary.
Like this:
int
critter_cmp (const void *v1, const void *v2)
{
const struct critter *c1 = v1;
const struct critter *c2 = v2;
return strcmp (c1->name, c2->name);
}
Similarly for the other two examples.