Search code examples
c++static-cast

Why we are using static_cast to NULL


When I try to study QP/CPP code I came across below line.

QTimeEvt *t; 
// ...
if (t == static_cast<QTimeEvt *>(0)) {

Why they are doing static_cast of 0? If they want to check NULL we can do that directly right?

This source code you can find out in

http://www.state-machine.com/qpcpp/qf__time_8cpp_source.html


Solution

  • Yeah, that's unnecessary, though it may be mandated by some style guide for "clarity", or it may be there to silence an overzealous static analysis tool.

    Of course, nowadays, we'd just write nullptr and leave it at that.