Opening and closing braces for if
, for
, or and while
statements should always be used even if the statement's body contains only a single statement.
...
Braces also help ensure that macros with multiple statements are properly expanded. Such a macro should be wrapped in a do-while
loop. (See PRE10-C. Wrap multistatement macros in a do-while loop.) However, when the do-while
loop is not present, braces can still ensure that the macro expands as intended.
...
Code Block | ||||
---|---|---|---|---|
| ||||
int login; if (invalid_login()) login = 0; else printf("Login is valid\n"); /* debuggingDebugging line added here */ login = 1; /* thisThis line always gets executed, regardless of a valid login! */ |
...