Why is there a performance warning on cast pointer to bool?

前端 未结 6 1948
花落未央
花落未央 2020-12-09 01:14

Extends.

I thought I was being cool when I did something like:

bool hasParent()
{
  return this->parentNode ;
}

Even with a (bool) cast, the

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 01:54

    Realistically i think they would optimize to the same, you can also try doing this:

    return this->parentNode != 0;
    

提交回复
热议问题