MISRA C:2012 Rule 14.1
A loop counter shall not have essentially floating type
Description
Rule Definition
A loop counter shall not have essentially floating type.
Rationale
When using a floating-point loop counter, accumulation of rounding errors can cause the actual number of iterations to be different than the number of iterations you expect. This rounding error can happen when a loop step that is not a power of the floating-point radix is rounded to a value that can be represented by a float.
Even if a loop with a floating-point loop counter appears to behave correctly on one implementation, it can give a different number of iterations on another implementation.
Polyspace Implementation
Polyspace® reports a violation of this rule if the essential type of a loop
counter variable is float
.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Control Statement Expressions |
Category: Required |
AGC Category: Advisory |