
3 Nov
2007
3 Nov
'07
6:28 p.m.
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).