MISRA Discussion Forums
8.14 and "involved in a decision to exit the loop" - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.14 Control statement expressions (https://forum.misra.org.uk/forumdisplay.php?fid=169)
+---- Thread: 8.14 and "involved in a decision to exit the loop" (/showthread.php?tid=961)



8.14 and "involved in a decision to exit the loop" - gs - 01-05-2013

Section 8.14 defines a loop counter as "an object, array element or member of a structure or union which"
  • 1. has scalar type,
    2. varies monotonically on each iteration of a given instance of a loop, and
    3. is involved in a decision to exit the loop.
My question is, "To what extent does the item in question need to be "involved in a decision to exit the loop"? For example, consider the code:
Code:
...
if( g(x) )
    break;
...
Is 'x' "involved in a decision to exit the loop"?

What of
Code:
...
if( h() )
    break;
...
where 'h()' returns a value based on, say, a static variable, 'q'; is 'q' "involved in a decision to exit the loop"?


Re: 8.14 and "involved in a decision to exit the loop" - misra-c - 01-07-2013

'x' is involved in the decision to exit the loop if the value returned by 'g' is dependent on the value of 'x'. For example:

Code:
bool g ( int x ) {    return x == 3; }         /* involved in decision to exit the loop */
bool g ( int x ) {    fn(x); return True; }   /* not involved in decision to exit the loop */

The same argument applies to 'h' and 'q'. If the value of 'h' returns a value that is dependent on 'q', then 'q' is involved in the decision to exit the loop.

In general the answer to this question will be undecidable, which is reflected in rules 14.1 and 14.2 being marked as undecidable. Analysis tools are likely to vary in whether they produce False Positives or False Negatives for these rules.