Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-03-12 20:53:31


----- Mensaje original -----
De: David Abrahams <dave_at_[hidden]>
Fecha: Domingo, Marzo 13, 2005 0:52 am
Asunto: [boost] Re: [review] hash functions

> Alberto Barbati <abarbati_at_[hidden]> writes:
>
> > Ah! And there's one more case in which we are helpless, although
> I'm
> > curious to see an implementation that exploits such latitude:
> the
> > wording used in the standard does not guarantee that the mapping
> from
> > pointers to integers always produce the same value over time. In
> other
> > words:
> >
> > char* p = new char;
> > size_t i1 = reinterpret_cast<size_t>(p);
> > size_t i2 = reinterpret_cast<size_t>(p);
> > assert(i1 == i2); // ???
> > char* q1 = reinterpret_cast<char*>(i1);
> > char* q2 = reinterpret_cast<char*>(i2);
> > assert(p == q1 && q1 == q2);
> >
> > The standard guarantees that the second assert passes, but says
> nothing
> > about the first assert.
>
> There are other cases too. reinterpret_cast could map all
> pointers to
> the same integer.

If you allow me to be a little pedantic, this is not
the case. reinterpret_cast<> guarantees back conversion,
so it can't possibly map every pointer into the same
integer.

As for the rest of your argument, I agree 100%.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk