提问人:user2986042 提问时间:7/21/2021 最后编辑:user2986042 更新时间:7/21/2021 访问量:451
“Expression Used in the condition always yields the same result”(条件中使用的表达式总是产生相同的结果)“C 语言中的警告 [已关闭]
"Expression Used in the condition always yields the same result" warning in C [closed]
问:
我想知道Misra警告的确切含义。这是我正在使用的一段代码。Expression Used in the condition always yields the same result
#define bool_new_timer_val (Time_cnt < 4sec)
if( (bool_new_timer_val == True) ||
(mystruct.bool_u8_status1 != 0x0) ||
((mystruct.bool_u8_status1 == 0x0) && (bool_old_timer == True)) ||
(mystruct.bool_u8_status2 == True) ||
(mystruct.bool_u8_status3 == True))
{
// update the logic
}
在运行 Misra 时,我收到警告为 .
问题出在线路上Expression 'mystruct.bool_u8_status1' used in the condition always yields the same result
((mystruct.bool_u8_status1 == 0x0) && (bool_old_timer == True))
我想知道这个警告是什么意思。我的猜测是该值始终设置为 .这是正确的理解吗?有什么建议吗?mystruct.bool_u8_status1
0x0
答:
1赞
Support Ukraine
7/21/2021
#1
查看您的代码:
(mystruct.bool_u8_status1 != 0x0) ||
((mystruct.bool_u8_status1 == 0x0) && (bool_old_timer == True)) ||
如果计算结果为 TRUE,则不计算第二行。mystruct.bool_u8_status1 != 0x0
如果计算结果为 FALSE,则代码等效于mystruct.bool_u8_status1 != 0x0
(FALSE) ||
((TRUE) && (bool_old_timer == True)) ||
归根结底,这很简单
((bool_old_timer == True)) ||
因此,请尝试编写如下代码:
(mystruct.bool_u8_status1 != 0x0) ||
(bool_old_timer == True) ||
评论
True
mystruct.bool_u8_status1
if
4sec