13-01-2022, 09:27 PM
Hello,
A user is surprised that his compiler diagnoses the following as being a violation of MISRA 2012 13.5:
int in_range(double a)
{
int result = 0;
if (a >= 10.0 && a <= 20.0) {
result = 1;
}
return result;
}
The reasoning behind the diagnostic is that with C99, floating point status bits (if implemented) are considered part of the program state, so floating point operations have implicit side effects. See the footnote in C99 5.1.2.3.
This kind of goes back to Directive 1.1 and various decisions about floating point.
Does everyone agree that this should be considered a violation? I would appreciate any other thoughts you may have.
Thanks,
-Greg
A user is surprised that his compiler diagnoses the following as being a violation of MISRA 2012 13.5:
int in_range(double a)
{
int result = 0;
if (a >= 10.0 && a <= 20.0) {
result = 1;
}
return result;
}
The reasoning behind the diagnostic is that with C99, floating point status bits (if implemented) are considered part of the program state, so floating point operations have implicit side effects. See the footnote in C99 5.1.2.3.
This kind of goes back to Directive 1.1 and various decisions about floating point.
Does everyone agree that this should be considered a violation? I would appreciate any other thoughts you may have.
Thanks,
-Greg
<t></t>