MISRA C++:2008 Rule 5-0-5
There shall be no implicit floating-integral conversions
Description
Rule Definition
There shall be no implicit floating-integral conversions.
Rationale
If you convert from a floating point to an integer type, you lose information. Unless you explicitly cast from floating point to an integer type, it is not clear whether the loss of information is intended. Additionally, if the floating-point value cannot be represented in the integer type, the behavior is undefined.
Conversion from an integer to floating-point type can result in an inexact representation of the value. The error from conversion can accumulate over later operations and lead to unexpected results.
Polyspace Implementation
The checker flags implicit conversions between floating-point types
(float
and double
) and integer types
(short
, int
, etc.).
This rule takes precedence over 5-0-4 and 5-0-6 if they apply at the same time.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required |
Version History
Introduced in R2013b