このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
MISRA C++:2008 Rule 6-5-4
The loop-counter shall be modified by one of: --, ++, -=n, or +=n ; where n remains constant for the duration of the loop.
説明
ルール定義
The loop-counter shall be modified by one of: --, ++, -=n, or +=n ; where n remains constant for the duration of the loop. 1
根拠
ループのループ カウンター修飾子が定数でない場合、ループが予期せずに終了し、想定に反した結果になる可能性があります。定数のインクリメントの場合は、ループの終了が予測可能になります。
Polyspace 実装
Polyspace® はループ カウンターの修飾子が定数でない場合は常にこの欠陥を報告します。また、"-=n" または "+=n" でループが修飾され、"n" がこのループ内で変更される場合も、Polyspace がこの欠陥を報告します。
トラブルシューティング
ルール違反が想定されるものの、Polyspace から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。
例
チェック情報
グループ: Statements |
カテゴリ: 必要 |
バージョン履歴
R2013b で導入
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.