Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2007-11-03 18:31:05


Peter Dimov wrote:
> David Abrahams:
>
> 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).
>
The standard says no such thing. It speaks of a pointer "suitably
converted". It doesn't say that reinterpret_cast is such a suitable
conversion; in fact, the definition of reinterpret_cast itself makes it
very clear that it is not.

A suitable conversion is for example the double static_cast that David
has shown.

Sebastian Redl


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