C and C++


LANG.STRUCT.LOOP.FPC : Float-typed Loop Counter

Summary

A FOR loop counter is a float, double, or long double.

Properties

Class Name Float-typed Loop Counter
Significance style
Mnemonic LANG.STRUCT.LOOP.FPC
Categories
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.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Float-typed Loop Counter"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

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 */
        /* ... */
    }
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.