This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix warnings in manual/examples/search.c


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]