如何整数类型隐式转换? [英] How are integer types converted implicitly?
问题描述
以下code在MISRA检查失败。具体的错误消息是:
(MISRA-C:2004年10.1 / R)整数类型的前pression的值应
不被隐式转换为不同的基本类型,如果它是
不转换到更广阔的整数类型相同的带符号的
块引用>的typedef枚举_MyEnum {一,二} MyEnum;
MyEnum MyVariable的;INT富(无效)
{
INT结果= 1; 如果(一== MyVariable的)//这里失败,MISRA-C:2004 10.1 / R
{
结果= 2;
}
返回结果;
}
- 为什么逻辑前pression转换?
- 这是怎么转化?
- 为什么code通过MISRA检查,当我换
一
和MyVariable的
?的修改的:编译器是TIMSP430 C / C ++编译器V4.0.0与包括MISRA规则检查
。解决方案我会怀疑一个编译器错误。您正在使用什么编译器? 这个帖子提到编译器故障而导致米斯拉10.1采用TI公司的编译器时/ R故障。
The following code fails on a MISRA check. The concrete error message is:
(MISRA-C:2004 10.1/R) The value of an expression of integer type shall not be implicitly converted to a different underlying type if it is not a conversion to a wider integer type of the same signedness
typedef enum _MyEnum { One, Two } MyEnum; MyEnum MyVariable; int foo(void) { int result = 1; if (One == MyVariable) // fails here with MISRA-C:2004 10.1/R { result = 2; } return result; }
- Why is the logical expression converted?
- What is converted here?
- Why does the code pass the MISRA check, when I swap
One
andMyVariable
?Edit: The compiler is a TI "MSP430 C/C++ Compiler v4.0.0" with included MISRA rules check.
解决方案I would suspect a compiler bug. What compiler are you using? This post mentions a compiler bug causing Misra 10.1/R failures when using TI's compiler.
这篇关于如何整数类型隐式转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!