Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
8.14 and "involved in a decision to exit the loop"
#1
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"?
Reply
#2
'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.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)