How does the following code work?

后端 未结 2 1373
逝去的感伤
逝去的感伤 2020-12-08 14:57
    #define TYPE_CHECK(T, S)                                     \\
    while (false) {                                              \\
      *(static_cast

        
2条回答
  •  一整个雨季
    2020-12-08 15:48

    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.

提交回复
热议问题