Re: Compile problem with delay_pools.c in 2.2.STABLE2

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Fri, 23 Apr 1999 02:12:42 +0200

Hmm.. the function as originally written is very messy. On many systems
a pointer (or even pointer offset) won't fit inside an int, or even be
possible to convert to an integer type.

If you want pointer comparisation, why not use the comparisation
operators instead?

Actually, doing anything but array pointer aritmetic or equivalence
tests is undefined due varianse of pointer types. You can't do aritmetic
with two different pointers, not even of the same type. Basically with
pointers you are limited to: storing/retreiving pointers, pointer
aritmetic combining one pointer and one or more integers, or equivalence
tests between two pointers.

Only when you know the environment where your program runs in detail,
you may be able to deduce further from pointers, or even convert them
back and forth from integer types to perform more advanced aritmetic
(like ordering).

/Henrik

David Luyer wrote:
>
> > My workaround patch follows. My (possibly horribly mistaken) assumption
> > is that the function only really needs to indicate whether or not the
> > pointers are equal.
>
> No ... b - a is for a less than, equal or greater comparison!
>
> It is not ANSI compliant to do pointer arithmetic with a void, so what
> should be done is
>
> return (char *)b - (char *)a;
>
> David.
>
> > *** src/delay_pools.c.orig Tue Apr 13 03:25:13 1999
> > --- src/delay_pools.c Thu Apr 22 20:35:00 1999
> > ***************
> > *** 114,120 ****
> > delayIdPtrHashCmp(const void *a, const void *b)
> > {
> > /* Sort by POINTER VALUE. */
> > ! return b - a;
> > }
> >
> > void
> > --- 114,120 ----
> > delayIdPtrHashCmp(const void *a, const void *b)
> > {
> > /* Sort by POINTER VALUE. */
> > ! return a != b;
> > }
> >
> > void
Received on Tue Jul 29 2003 - 13:15:57 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:12:06 MST