This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch: convenience routines for hashtab.c
- To: vonbrand at sleipnir dot valparaiso dot cl (Horst von Brand)
- Subject: Re: Patch: convenience routines for hashtab.c
- From: Brad Lucier <lucier at math dot purdue dot edu>
- Date: Thu, 4 May 2000 08:52:48 -0500 (EST)
- Cc: lucier at math dot purdue dot edu (Brad Lucier), gcc-patches at gcc dot gnu dot org, mark at codesourcery dot com
> 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