Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Side effects in floating point comparisons
#1
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
<t></t>
Reply
#2
Thank you for bringing this to our intention.  It was not our intention that floating point status bits were included in our definition of "persistent side effects".  This will be clarified in a later version.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)