这是代码:
test.cpp
unsigned short x;
bool y;
if ((x==1)&& y)
{
...
}
else
{
...
}
我收到一条 lint 消息:
Note 912 Implicit binary conversion from int
to unsigned int [MISRA Rule 48]
为什么?以及如何避免这种情况?
最佳答案
您正在比较 x
(默认为 unsigned Short
)和 1
(默认为 int
)。因此你得到了隐式二进制转换的东西。
给你的编译器一个提示,表明你确实想要将x
与另一个无符号
值进行比较:
if ((x==1U) && y)
关于c++ - 如何解决此 lint 警告 "Implicit binary conversion from int to unsigned int",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35123841/