Synopsis: | All control statements shall be fully brace enclosed. This means that all "if", "while", "for", "do" and "switch" statements are followed by a brace-enclosed compound statement. |
Language: | C |
Severity Level: | 5 |
Category: | Statement and Blocks |
Description: |
Justification By using braces a visible grouping of statements is created. Programming errors can be caused when the body of a control statement without braces is expanded from one statement to many. Example 1 if (...) if (...) /* WRONG */ { ... } else /* This "else" belongs to the second "if" and not to the first "if".*/ { ... } Example 2 if (...) { /* RIGHT */ if (...) { ... } } else { ... } |