![]() |
|
MISRA-C:2004 Rule 14.9: (Required) |
|
||||
![]() | |||||||
Note that the layout for compound statements and their enclosing braces should be determined from the style guidelines. The above is just an example.if(test1){x=1;/* Even a single statement must be in braces */}elseif(test2)/* No need for braces in else if */{x=0;/* Single statement must be in braces */}elsex=3;/* This was (incorrectly) not enclosed in braces */y=2;/* This line was added later but, despite the appearance (from the indent) it is actually not part of the else, and is executed unconditionally */
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. |
Related rules:
| Rule 14.8 | The statement forming the body of a switch, while, do ... while or for statement shall be a compound statement. |
|
||
(c) The Motor Industry Research Association, 2004
|
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2 © 2013 Programming Research www.programmingresearch.com |
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |