8.14 and "involved in a decision to exit the loop"

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

8.14 and "involved in a decision to exit the loop"

Post by gs » Wed May 01, 2013 3:23 pm

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: Select all

...
if( g(x) )
    break;
...
Is 'x' "involved in a decision to exit the loop"?

What of

Code: Select all

...
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"?

misra-c
Posts: 569
Joined: Thu Jan 05, 2006 1:11 pm

Re: 8.14 and "involved in a decision to exit the loop"

Post by misra-c » Mon Jul 01, 2013 11:05 am

'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: Select all

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

Post Reply

Return to “8.14 Control statement expressions”