Consider the following declarations of a pair of related structs. The descendant class adds no member variables, and the only member function is a constructor that does noth
While this particular example is safe on all modern platforms and compilers I am familiar with, it is not safe in general and it is an example of a bad code.
UPD. Both Base and Descendant are standard layout types. So it is a requirement of the standard that a pointer to Descendant can be correctly reinterpret_cast to a pointer to Base, that means no padding in front of the structure is allowed. But there is no any requirement in C++ standard for padding at the end of a structure, so it is compiler-dependent. There is also the standard proposal to explicitly mark this behavior as undefined. http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1504