Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-11-03 14:28:28


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;
};

and the standard requires a reinterpret_cast to yield a pointer to the first
element (9.2/17).

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).


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