This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
[这个问题有关,但并不等同于这一个 ]
我的编译器警告隐式转换或将某些类型转换为bool,而显式转换不会产生警告:
long t = 0;
bool b = false;
b = t; // performance warning: forcing long to bool
b = (bool)t; // performance warning
b = bool(t); // performance warning
b = static_cast<bool>(t); // performance warning
b = t ? true : false; // ok, no warning
b = t != 0; // ok
b = !!t; // ok
Run Code Online (Sandbox Code Playgroud)
这是使用Visual C++ 2008但我怀疑其他编译器可能有类似的警告.
所以我的问题是:铸造/转换的性能影响是什么bool?在某些情况下(例如,对于某些目标体系结构或处理器),显式转换是否具有更好的性能?隐式转换是否会以某种方式混淆优化器?
微软对其警告的解释并不是特别有用.他们暗示有充分的理由,但他们没有解释.