MISRA C Rule­6.1 0635 Rule­7.2 1281

2025-10-13 19:09:40

struct/union中的位域被声明为除int、signed int或unsigned int外的其他类型 ;

整型常量是无符号类型,但没有使用后缀符'U' 。

工具/原料

Rule­6.1 0635 Rule­7.2 1281

MISRA C:2012

Rule­6.1 0635

规则与等级对应关系(QAC)

MISRA C Rule­6.1 0635 Rule­7.2 1281

0635 [E] Bit-fields in this struct/union have been declared with types other than int, signed int or unsigned int. 

struct/union中的位域被声明为除int、signed int或unsigned int外的其他类型

根据ISO:C 标准,位域只能定义为以下类型: 

int/unsigned int/signed int。

有些编译器支持一些其他整型,比如char,short和enum。这属于语言的扩展,且是不可移植的。

在struct或union声明中,无论含有多少非标准位域,消息0635只会生成一次。

MISRA C Rule­6.1 0635 Rule­7.2 1281

编程规范修改举例

MISRA C Rule­6.1 0635 Rule­7.2 1281

Rule­7.2 1281

规则与等级对应关系(QAC)

MISRA C Rule­6.1 0635 Rule­7.2 1281

1281 Integer literal constant is of an unsigned type but does not include a "U" suffix. 

这是整型常量是无符号类型,但没有使用后缀符 'U' 。

注意:一个整数常量的类型,依赖于常量的值大小、'int' 型被实现的大小(即是说 'int' 型是16位还是32位)以及出现的后缀符。

官方示例

MISRA C Rule­6.1 0635 Rule­7.2 1281

编程规范修改举例

MISRA C Rule­6.1 0635 Rule­7.2 1281

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢