Mail Archives: djgpp-workers/2004/01/26/05:31:02
On Mon, 26 Jan 2004, Eli Zaretskii wrote:
> I'd prefer that the part that does pointer arithmetics would still
> cast the pointer to a char *.
Like this?
Index: bsearch.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/bsearch.c,v
retrieving revision 1.1
diff -u -r1.1 bsearch.c
--- bsearch.c 26 Dec 1994 20:35:04 -0000 1.1
+++ bsearch.c 26 Jan 2004 10:26:49 -0000
@@ -3,24 +3,23 @@
#include <libc/unconst.h>
void *
-bsearch(const void *key, const void *base0, size_t nelem,
+bsearch(const void *key, const void *base, size_t nelem,
size_t size, int (*cmp)(const void *ck, const void *ce))
{
- char *base = unconst(base0, char *);
int lim, cmpval;
- void *p;
+ const void *p;
for (lim = nelem; lim != 0; lim >>= 1)
{
- p = base + (lim >> 1) * size;
+ p = (const char *)base + (lim >> 1) * size;
cmpval = (*cmp)(key, p);
if (cmpval == 0)
- return p;
+ return unconst(p, void *);
if (cmpval > 0)
{ /* key > p: move right */
- base = (char *)p + size;
+ base = (const char *)p + size;
lim--;
} /* else move left */
}
- return 0;
+ return NULL;
}
--
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/
- Raw text -