October 2004
Intermediate to advanced
240 pages
6h 22m
English
reinterpret_castLies have short legs (German and Romanian proverb): Don’t try to use reinterpret_cast to force the compiler to reinterpret the bits of an object of one type as being the bits of an object of a different type. That’s the opposite of maintaining type safety, and reinterpret_cast isn’t even guaranteed to do that or anything else in particular.
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 compiler—to the point of being determined to pick an argument with the compiler’s carefully maintained type information. Compilers ...