MISRA C:2012 Rule 1.3
There shall be no occurrence of undefined or critical unspecified behaviour
描述
规则定义
There shall be no occurrence of undefined or critical unspecified behaviour 1 .
理由
导致未定义或关键性未指定行为的 C 代码可能会产生意外或错误的结果。此类代码在不同实现中可能表现不同。代码中未定义行为引发的问题可能难以分析,因为编译器可能会在假设未定义行为不会发生的情况下对代码进行优化。
注意
MISRA C:2012 中的许多规则针对特定的未定义或关键的未指定行为。本规则适用于任何未定义或未明确指定的临界行为,且该行为未在其他任何规则中进行说明。
Polyspace 实现
Polyspace® 标记这些未定义或关键未定义行为的实例:
在位字段上使用
offsetof
。当第二个参量不是第一个参量的
struct
字段时,使用offsetof
。在未指定标识符的情况下使用
defined
。使用的宏在展开时包含
defined
运算符。使用不完整类型的数组。
以错误数量的参量调用类似宏的函数(仅限 C90)。
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
组:标准 C 环境 |
类别:必需 |
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.