逻辑运算符和位运算符警告混淆-iOS
我有一个if-else语句,其中有两个完全正确的参数,但是第二个if给了我这个警告: 对常量操作数使用逻辑“&&” 使用的代码是:逻辑运算符和位运算符警告混淆-iOS,ios,if-statement,operators,bit-manipulation,Ios,If Statement,Operators,Bit Manipulation,我有一个if-else语句,其中有两个完全正确的参数,但是第二个if给了我这个警告: 对常量操作数使用逻辑“&&” 使用的代码是: else if ( !IS_WIDESCREEN && UIInterfaceOrientationPortrait) //No Warning or error { } else if(IS_WIDESCREEN && UIInterfaceOrientationLandscapeRight) //Gives me the abo
else if ( !IS_WIDESCREEN && UIInterfaceOrientationPortrait) //No Warning or error
{
}
else if(IS_WIDESCREEN && UIInterfaceOrientationLandscapeRight) //Gives me the above warning
{
}
注:IS_宽屏-根据iPhone 5屏幕的尺寸定义
知道为什么吗
///编辑:
添加了我如何定义iPhone5
#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
我想应该是这样
else if ( !IS_WIDESCREEN && (interfaceOrientation == UIInterfaceOrientationPortrait)) {
// ....
} else if(IS_WIDESCREEN && (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
// ....
}
如果您在
内部使用此选项,则应在中使用AutoRotateTointerFaceOrientation
,因为您将常量值与是宽屏的进行比较,如果您在逻辑&
表达式中使用常量,则会收到警告,因为该常量不相关。假设常数是非负的。if(x&&non-neg常量)
的结果与if(x)
的结果相同。同样,如果常数为零,if(x&&0)
将永远不会为真
因此,编译器警告您,并暗示您可能正在尝试执行逐位操作,检查特定位是否已设置。当您说它是用iPhone 5屏幕的测量值定义的时,您的意思是它只是硬编码到该大小,还是定义中的另一个逻辑检查?为您添加了代码,所以你可以看到我在shouldAutoRotateToInterfaceOrientation
方法中所做的是什么?是的,很抱歉,我忘了提到这一点!!如果SO取消了时间限制,我将接受:-)
else if ( !IS_WIDESCREEN && (interfaceOrientation == UIInterfaceOrientationPortrait)) {
// ....
} else if(IS_WIDESCREEN && (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
// ....
}