主要内容

MISRA C:2012 Rule 10.6

The value of a composite expression shall not be assigned to an object with wider essential type

描述

规则定义

The value of a composite expression shall not be assigned to an object with wider essential type 1 .

理由

复合表达式是使用复合运算符的非常量表达式。在基本类型模型中,复合运算符是:

  • 乘法运算符(*/%

  • 加法运算符(二进制 +、二进制 -

  • 位运算符(&|^

  • 移位运算符(<<>>

  • 条件运算符(?:

一元运算符(例如 ~)和一元 +- 也被视为复合运算符。

如果将复合表达式的结果赋值给更大的类型,则隐式转换可能会导致丢失值、符号、精确度或布局。

有关基本类型的详细信息,请参阅Essential Types in MISRA C Rules 10.x

故障排除

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

检查信息

组:基本类型模型
类别:必需
AGC 类别:建议

版本历史记录

全部展开


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.