From: David Abrahams (dave_at_[hidden])
Date: 2005-03-12 18:52:39
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
> 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. I'm saying what Peter's saying. This is
non-portable territory; don't lose sleep over it; practically speaking
it will work most places; everywhere else we'll fix it.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk