MISRA C:2023 Rule 6.1
Bit-fields shall only be declared with an appropriate type
自 R2024a 起
描述
规则定义
Bit-fields shall only be declared with an appropriate type 1 .
理由
将 int
用于位域类型是由实现定义的,因为 int
类型的位域可以是 signed
或者 unsigned
。
在 C90 中不允许使用 enum
、short char
或任何其他类型的位域,因为行为是未定义的。
在 C99 中,实现可能会定义位域声明中允许使用的其他整数类型。
Polyspace 实现
检查项会标记除以下允许类型之外用于位域的数据类型:
C90:
signed int
或unsigned int
(或解析为这些类型的typedef
)C99:
signed int
、unsigned int
或_Bool
(或解析为这些类型的typedef
)
结果取决于分析中使用的 C 标准版本。请参阅 C 标准版本 (-c-version)
。
故障排除
如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected。
检查信息
组:类型 |
类别:必需 |
AGC 类别:必需 |
版本历史记录
在 R2024a 中推出
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace® Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.