【发布时间】:2012-05-14 19:17:10
【问题描述】:
首先,这类似于:How are integer types converted implicitly?,但带有不同的 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.
编译器是否正确(未识别缺陷)或静态分析工具?
【问题讨论】:
-
同样的代码,同样的错误,你的错误报告只是有点冗长。我看不出你的代码 sn-ps 有什么区别。
-
我很想知道你从你的工具供应商那里得到了什么回复,但这看起来工具坏了。