Exceptions
Team LiB
Previous Section Next Section

Exceptions

Some low-level system-specific programming might force you to use reinterpret_cast to stream bits in and out some port, or to transform integers in addresses. Use unsafe casting as rarely as you can and only in well-hidden functions that abstract it away, so as to make your code ready for porting with minimal changes. If you need to cast among unrelated pointer types, prefer casting via void* instead of using reinterpret_cast directly. That is, instead of



T1* p1 = ... ;


T2* p2 = reinterpret_cast<T2*>( p1 );



write



T1* p1 = ... ;


void* pV = p1;


T2* p2 = static_cast<T2*>( pV );



    Team LiB
    Previous Section Next Section