C and C++


LANG.STRUCT.LOOP.FPC : 浮動小数点型のループカウンタ

要旨

for文のループカウンターが floatdoublelong double のいずれかの型です。

プロパティ

クラス名 Float-typed Loop Counter
日本語クラス名 浮動小数点型のループカウンタ
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.LOOP.FPC
カテゴリー
MisraC2023 MisraC2023:14.1 A loop counter shall not have essentially floating type
Misra2012 Misra2012:14.1 A loop counter shall not have essentially floating type
Misra2004 Misra2004:13.4 The controlling expression of a for statement shall not contain any objects of floating type
AUTOSARC++14 AUTOSARC++14:A6-5-2 A for loop shall contain a single loop-counter which shall not have floating-point type.
MisraC++2008 MisraC++2008:6-5-1 A for loop shall contain a single loop-counter which shall not have floating type.
MisraC++2023 MisraC++2023:9.5.1 Legacy for statements should be simple
TS17961 TS17961:5.23-usrfmt 5.23. Including tainted or out-of-domain input in a format string
CERT-C CERT-C:FLP30-C Do not use floating-point variables as loop counters
JSF++ JSF++:197 Floating point variables shall not be used as loop counters.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Float-typed Loop Counter"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void lang_struct_loop_fpc(void){
    float fc;
    int i;

    for ( fc = 0.0f; fc < 1.0f; fc += 0.01f){ /* 'Float-typed Loop Counter' warning issued here */
        /* ... */
    }

    for ( i = 0; i < 100; i++){                                      /* integer loop counter */
        /* ... */
    }
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。