考虑以下代码片段:
main()
{
bool flag = true; //line 1
flag &= funcReturningBool(); //line 2
flag &= funcReturningBool2();
flag &= funcReturningBool3();
//....
//....
//....
//so many such cases
}
bool funcReturningBool()
{
bool ret = false;
// my logic which may (not) modify ret
return ret;
}
bool funcReturningBool2()
{
bool ret = false;
// my logic which may (not) modify ret
return ret;
}
bool funcReturningBool3()
{
bool ret = false;
// my logic which may (not) modify ret
return ret;
}
静态代码分析器工具指出了以下问题(第 2 行):
"按位运算符正在应用于有符号类型。结果值可能与预期不同。 "
有人可以指出我做错了什么吗?还要规定一些有用/合乎逻辑的替代方法来实现相同的目标!