|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2007-11-03 19:39:29
on Sat Nov 03 2007, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
> David Abrahams:
>
>>> (A reinterpret_cast<char*>( p ) is indirectly required to work when
>>> p is a pointer to a class type,
>>
>> Where does the standard say that, and what do you mean by "work?"
>
> Consider this code:
>
> class X;
>
> char * f( X * p )
> {
> return reinterpret_cast<char*>( p );
> }
>
> This must give you a char* pointing to the first byte of *p because X's
> definition may be
>
> struct X
> {
> char v;
> };
Any POD struct will do.
> and the standard requires a reinterpret_cast to yield a pointer to
> the first element (9.2/17).
Nice.
> Because of ODR, the complete type case must be compiled in the same
> way, even when X happens to not have a first member of type char
> (link-time code generation aside).
Right.
OK, then, look for a core issue from me. It's ridiculous that
reinterpret_cast should be defined to be so close to what everyone
thinks it is, and yet, not quite.
-- Dave Abrahams Boost Consulting http://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