![]() |
![]() |
2461 | ![]() |
||||
![]() | |||||||
| Control flow | |||||||
The control variable in this loop construct has been declared at file scope. QAC attempts to identify a loop control variable when analysing for loops and whileloops. Sometimes this is not possible because the concept of a loop control variable is not an intrinsic feature of the C language and loop control may depend on more than one variable. However in most situations, control of a loop is associated with a single local variable and it is important that modification of its value is clearly understood. If a loop control variable is declared at file scope it will have linkage. This means that confusion can arise if the variable happens to be modified by another function and that function is called from within the loop. For example:
/*PRQA S 2017,3120,3408,3447 ++*/
extern int si;
extern void f2(void);
extern void f1(void)
{
for (si=0; si<3; si++) /* Message 2461 */
{
f2();
}
}
extern void f2(void)
{
--si; /* Loop will never terminate ! */
}
No MISRA-C:2004 Rules applicable to message 2461
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |