
3 Nov
2007
3 Nov
'07
10:31 p.m.
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