Discussion
Team LiB
Previous Section Next Section

Discussion

Recall: If you lie to the compiler, it will get its revenge.

Henry Spencer

reinterpret_cast reflects the strongest assumption a programmer can make about object representation, namely that the programmer knows better than the compilerto the point of being determined to pick an argument with the compiler's carefully maintained type information. Compilers will shut up if you tell them to, but use of force should be a last resort. Avoid assuming how data is represented, because such assumptions dramatically affect the safety and reliability of your code.

Besides, the reality is that reinterpret_cast's effects are worse than reinterpreting objects' bit patterns (which would be bad enough). Except that some conversions are guaranteed to be reversible, its effects are actually implementation-defined, so you don't know if it will do even that. It is unreliable and nonportable.

    Team LiB
    Previous Section Next Section