![]() |
![]() |
2471 | ![]() |
||||
![]() | |||||||
| Control flow | |||||||
QAC has been unable to identify a loop control variable in this 'for-loop'. The most common style of 'for-loop' is controlled by a single variable which is initialised in the first expression, tested against a constant value in the second expression and incremented in the third expression. The behaviour of such a loop is conventional and usually well understood. However the C language does not define the concept of a 'loop control variable' and imposes no constraints on the nature of the 3 expressions or the relationships between them. Message 2472 is generated if there appears to be more than one loop control variable. Message 2471 is generated when QAC fails altogether to identify loop control variables. Either message is an indication that the loop is controlled in a complex or confusing way. For example:
/*PRQA S 769,2017,2213,2214,3120,3132,3198,3199,3203,3227,3408,3418,3447 ++*/
extern int ia[100];
extern void f1(int b, int c, int d)
{
int a;
int x;
for ( a = 0; a < 10; ++a) { } /* */
for ( a = 0; a < b; ++a) { } /* */
for ( b = 0; a < b; ++b) { } /* */
for ( a = 0; ia[a] < b; ++a) { } /* */
for ( a = 0; a < b; ++c) { } /* Message 2471 */
for ( a = 0; b <= c; d++ ) { } /* Message 2471 */
for ( a = 0; b <= c; a++ ) { } /* Message 2471 */
for ( a = b, x = c; (a < 10) && (x < 10); ++a, ++x) { } /* Message 2472 */
}
MISRA C:2012 Rules applicable to message 2471:
| Rule-14.2 (Required) | A for loop shall be well-formed |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |