![]() |
|
MISRA C:2012 Rule-15.6: (Required) |
|
||||
![]() | |||||||
Amplification:
The body of an iteration-statement (while, do ... while or for) or a selection-statement (if, else, switch) shall be a compound-statement.
Exception:
An if statement immediately following an else need not be contained within a compound statement.
Example Code:
#include "misra.h"
#include "m3cmex.h"
extern int16_t rule_1506( void )
{
int16_t n = 0;
if ( s16a == 0 )
{
s16c += 4;
}
else if ( s16a == 1 )
{
if ( s16b > 1 )
{
++s16b;
}
}
else
{
++s16c;
}
if ( s16b == 2 )
s16c += 3; /* 2212 */
else
n = 2; /* 2212 */
if ( s16b == 5 ) n = 6; /* 2214 */
else n = n - s16a; /* 2214 */
if ( n > 5 ) /* 3402 */
if ( s16b > 10 ) /* 2212 */
{
s16a = 1;
}
else
{
s16a = 2;
}
for ( n = 0; n < 5; n++ )
++s16a; /* 2212 */
for ( n = 0; n < 5; n++ ) ++s16a; /* 2214 */
n = get_s16();
while ( n < 5 )
++n; /* 2212 */
do n++; while ( n < 9 ); /* 2214 */
return s16a;
}
QAC messages that encompass this guideline:
| 2212 | Body of control statement is not enclosed within braces. |
| 2214 | Body of control statement is on the same line and is not enclosed within braces. |
| 3402 | Braces are needed to clarify the structure of this 'if'-'if'-'else' statement. |
|
||
(c) The Motor Industry Research Association, 2012
|
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0 © 2013 Programming Research www.programmingresearch.com |
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |