#define TYPE_CHECK(T, S) \\
while (false) { \\
*(static_cast
Quite a fancy hack - the purpose of the macro seems to be to check if the type S
is assignable to (i.e., is a subclass of) the type T
. If it is not, the pointer cast from S*
to T*
will produce a compiler error. The while (false)
prevents the code from actually having any other effect.
Yes, but the compiler still performs syntax & semantic checks on the loop contents. So if something is wrong (i.e. the implicit type conversion from S*
to T*
is illegal, which happens if T
is neither S
nor a base class of S
), compilation fails. Otherwise, the quality of the resulting machine code is not affected since the optimizer will detect the nonreachable code and remove it silently.