首先,这类似于:整数类型如何隐式转换?但有不同的 MISRA 警告。
编译器不会生成 MISRA 错误,但静态分析工具会生成。我正在处理工具制造商的票。
鉴于:
#include <stdio.h>
enum Color {RED, VIOLET, BLUE, GREEN, YELLOW, ORANGE};
int main(void)
{
enum Color my_color;
my_color = BLUE;
if (my_color == YELLOW) // Generates MISRA violation, see below.
{
printf("Color is yellow.\n");
}
else
{
printf("Color is not yellow.\n");
}
return 0;
}
if
静态分析工具正在为语句生成 MISRA 违规:
MISRA-2004 Rule 10.1 violation: implicitly changing the signedness of an expression.
Converting "4", with underlying type "char" (8 bits, signed),
to type "unsigned int" (32 bits, unsigned) with different signedness.
编译器是否正确(未识别缺陷)或静态分析工具?