This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Fix warnings in manual/examples/search.c
- From: Andreas Jaeger <aj at suse dot de>
- To: libc-alpha at sources dot redhat dot com
- Date: Wed, 16 May 2012 13:24:59 +0200
- Subject: Fix warnings in manual/examples/search.c
Our example produces quite some warnings:
gcc -Wall -c search.c
search.c: In function âfind_critterâ:
search.c:83:7: warning: passing argument 5 of âbsearchâ from incompatible pointer type [enabled by default]
In file included from search.c:18:0:
/usr/include/stdlib.h:755:14: note: expected â__compar_fn_tâ but argument is of type âint (*)(const struct critter *, const struct critter *)â
search.c: In function âmainâ:
search.c:102:41: warning: passing argument 4 of âqsortâ from incompatible pointer type [enabled by default]
In file included from search.c:18:0:
/usr/include/stdlib.h:761:13: note: expected â__compar_fn_tâ but argument is of type âint (*)(const struct critter *, const struct critter *)â
I propose the following change that does not give any warnings.
Ok to commit?
Andreas
2012-05-16 Andreas Jaeger <aj@suse.de>
* manual/examples/search.c (critter_cmp): Change signature to
avoid warnings.
* manual/string.texi (Collation Functions): Likewise.
diff --git a/manual/examples/search.c b/manual/examples/search.c
index e376567..6a10af0 100644
--- a/manual/examples/search.c
+++ b/manual/examples/search.c
@@ -53,8 +53,11 @@ int count = sizeof (muppets) / sizeof (struct critter);
/* This is the comparison function used for sorting and searching. */
int
-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);
}
diff --git a/manual/string.texi b/manual/string.texi
index 5051f54..7abf46b 100644
--- a/manual/string.texi
+++ b/manual/string.texi
@@ -1370,8 +1370,11 @@ efficiently using @code{strxfrm}.)
/* @r{This is the comparison function used with @code{qsort}.} */
int
-compare_elements (char **p1, char **p2)
+compare_elements (const void *v1, const void *v2)
@{
+ char **p1 = (char **)v1;
+ char **p2 = (char **)v2;
+
return strcoll (*p1, *p2);
@}
@@ -1462,8 +1465,11 @@ struct sorter @{ char *input; char *transformed; @};
@r{to sort an array of @code{struct sorter}.} */
int
-compare_elements (struct sorter *p1, struct sorter *p2)
+compare_elements (const void *v1, const void *v2)
@{
+ struct sorter *p1 = (struct sorter *)v1;
+ struct sorter *p2 = (struct sorter *)v2;
+
return strcmp (p1->transformed, p2->transformed);
@}
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 NÃrnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix ImendÃrffer,HRB16746 (AG NÃrnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126