This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Re: Patch: convenience routines for hashtab.c


> No problem, as this is a hash value and most objects will differ in address
> inside 4Gb, at least for a while ;-). I'd do something like:
> 
> static hashval_t
> hash_pointer (p)
>      const void *p;
> {
>   return (hashval_t) ((long) p >> 3);
> }
> 
> This way, you loose the last 3 bits, which are very likely to be zeroes
> anyway (malloc()ed objects are usually aligned at 8 byte boundaries, isn't
> it?), and shift in some (perhaps significant) bits from the high half. The
> intermediate cast should also get rid of the warning. And the above will
> also work fine where longs and pointers are the same size, just rotating
> the last 3 zeroes to the top.

It seems that the most portable way would be to use intptr_t as 
hashval_t.  This would have been better for many other places where
a pointer is cast to an integer for printing, too, but I can't find
any place in the compiler where intptr_t is used.  Is it not available
everywhere?

Brad

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