[英]MISRA-C warning during initialization enum type
Following enum defined in my code 按照我的代码中定义的枚举
typedef enum e_gpio_pin
{
GPIO_PIN_1 = 1, /*!< pin 1 */
GPIO_PIN_2, /*!< pin 2 */
GPIO_PIN_3, /*!< pin 3 */
GPIO_PIN_4, /*!< pin 4 */
GPIO_PIN_5, /*!< pin 5 */
GPIO_PIN_6, /*!< pin 6 */
GPIO_PIN_7, /*!< pin 7 */
GPIO_PIN_8, /*!< pin 8 */
GPIO_PIN_9, /*!< pin 9 */
GPIO_PIN_10, /*!< pin 10 */
GPIO_PIN_FIRST = GPIO_PIN_1, /*!< first pin */
GPIO_PIN_LAST = GPIO_PIN_10 /*!< last pin */
} T_GPIO_PIN;
Now below line have used to initialize the variable. 现在下面的行已用于初始化变量。
static const T_GPIO_PIN ioPin = GPIO_PIN_9;
and i got below warning 我得到了警告
An expression value of essential type 'Essentially Enum' is assigned to an object of essential type 'Essentially Enum' comment : MISRA 10.3 (C90-2012 req.) 必需类型'Essentially Enum'的表达式值分配给必需类型'Essentially Enum'的对象注释:MISRA 10.3(C90-2012 req。)
is anyone have idea how can i resolve this warning? 有谁知道我该如何解决此警告?
Since the enumeration constant GPIO_PIN_9
belongs to T_GPIO_PIN ioPin
they both have the same "essentially enum" type. 由于枚举常量GPIO_PIN_9
属于T_GPIO_PIN ioPin
因此它们都具有相同的“基本枚举”类型。 This is explained in MISRA-C:2012 appendix D.5 and D.6. MISRA-C:2012附录D.5和D.6中对此进行了说明。 In MISRA terms, your enum is a named enum (*) of type enum<i>
and its enumeration constants are of the same type. 用MISRA术语来说,您的枚举是enum<i>
类型的命名枚举 (*),其枚举常量是同一类型。
You would only get problems if you tried to assign an enum some values that are enumeration constants of another enum type. 如果您尝试为枚举分配一些值,这些值是另一个枚举类型的枚举常量,则只会出现问题。 I suppose the tool might get confused because you both used an enum tag and a typedef, perhaps it thinks that enum e_gpio_pin
and T_GPIO_PIN ioPin
are distinct enum types. 我想该工具可能会感到困惑,因为您都使用了枚举标签和typedef,也许它认为enum e_gpio_pin
和T_GPIO_PIN ioPin
是不同的枚举类型。
There is nothing wrong with your code as far as MISRA is concerned. 就MISRA而言,您的代码没有错。 Resolve the warning by posting a bug report to your tool vendor. 通过向您的工具供应商发布错误报告来解决警告。 A work-around for the tool bug might be to remove the enum tag. 解决该工具错误的方法是删除枚举标记。
(*) See appendix D.5 (*)见附录D.5
A named enum type is an enumeration which has a tag or which is used in the definition of any object, function or type; 命名枚举类型是具有标签或用于任何对象,函数或类型的定义的枚举;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.