monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] pointer arithmetics in C++


From: Nathaniel Smith
Subject: Re: [Monotone-devel] pointer arithmetics in C++
Date: Fri, 15 Sep 2006 17:57:41 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

On Fri, Sep 15, 2006 at 10:17:05PM +0200, Markus Schiltknecht wrote:
> Hi,
> 
> I know, I know, it's evil. I want to do some pointer arithmetics 
> anyway... I need to build a hash or digest or something from three 
> 'unsigned int' values and a pointer.

Is it really the pointer that you need to hash, not the value it
points to?  Could you give more details about what exactly you're
trying to do? :-)

If that's really what you want, you need something like

  x1 ^ x2 ^ x3 ^ reinterpret_cast<int>(my_pointer);

(Or perhaps multiplication would be better, or something, hash
functions are not that easy to design.)

Except that this assumes that pointers and integers are the same width
on your machine, i.e., it's not 64-bit safe, which is Bad.

This looks like a decent summary of the different new-style casts:
  http://www.codeguru.com/forum/showthread.php?t=312456

-- Nathaniel

-- 
"On arrival in my ward I was immediately served with lunch. `This is
what you ordered yesterday.' I pointed out that I had just arrived,
only to be told: `This is what your bed ordered.'"
  -- Letter to the Editor, The Times, September 2000




reply via email to

[Prev in Thread] Current Thread [Next in Thread]