主要内容

MISRA C:2012 Rule 6.1

Bit-fields shall only be declared with an appropriate type

描述

规则定义

Bit-fields shall only be declared with an appropriate type 1 .

理由

int 用于位字段类型是由实现定义的,因为 int 类型的位字段可以是 signed 或者 unsigned

在 C90 中不允许使用 enumshort char 或任何其他类型的位字段,因为行为是未定义的。

在 C99 中,实现可能会定义位字段声明中允许使用的其他整数类型。

Polyspace 实现

检查项会标记除以下允许类型之外用于位字段的数据类型:

  • C90:signed intunsigned int(或解析为这些类型的 typedef

  • C99:signed intunsigned int_Bool(或解析为这些类型的 typedef

结果取决于分析中使用的 C 标准版本。请参阅 C 标准版本 (-c-version)

故障排除

如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示

检查信息

组:类型
类别:必需
AGC 类别:必需

版本历史记录

在 R2014b 中推出


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.