我有一个if else语句,其中有两个完全正确的论点,但是第二个if给了我这个警告:
常量操作数中逻辑&&的使用
所用的代码是:
else if ( !IS_WIDESCREEN && UIInterfaceOrientationPortrait) //No Warning or error
{
}
else if(IS_WIDESCREEN && UIInterfaceOrientationLandscapeRight) //Gives me the above warning
{
}注意: IS_WIDESCREEN -是用iPhone 5屏幕的测量定义的。
知道这是为什么吗?
/编辑:
添加了我如何定义iPhone 5的
#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )整件事就在这个方法里面:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration发布于 2012-10-11 22:14:10
我觉得应该是
else if ( !IS_WIDESCREEN && (interfaceOrientation == UIInterfaceOrientationPortrait)) {
// ....
} else if(IS_WIDESCREEN && (interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
// ....
} 如果您在shouldAutoRotateToInterfaceOrientation中使用此方法,因为您要将常量值与IS_WIDESCREEN进行比较
发布于 2012-10-11 22:19:34
如果在逻辑&&表达式中使用常量,则会得到警告,因为该常量与此无关。假设常数是非负的。if (x && non-neg-constant)的结果与if (x)的结果完全一致。同样,如果常数为零,则if (x && 0)永远不会为真。
因此,编译器警告您,并暗示您可能正在尝试按位操作,检查某个特定位,以查看是否设置了该位。
https://stackoverflow.com/questions/12849255
复制相似问题