主要内容

MISRA C:2012 Rule 6.2

Single-bit named bit-fields shall not be of a signed type

描述

规则定义

Single-bit named bit-fields shall not be of a signed type 1 .

理由

根据 C99 标准第 6.2.6.2 节,单比特的有符号位字段只有一个符号位,没有值位。在任何整数表示法中,零值位都不能指定有意义的值。

因此,单比特有符号位字段不太可能以有用的方式运行。它的存在很可能表明程序员存在困惑。

尽管 C90 标准对于类型的表示没有提供太多细节,但那些单比特位字段注意事项同样适用。

Polyspace 实现

此规则不适用于未命名的位字段,因为其值无法被访问。

故障排除

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

检查信息

组:类型
类别:必需
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.