...
This compliant solution takes advantage of the compiler's ability to remove unreachable (dead) code. The code inside the if block must still stay remain acceptable to the compiler. If other parts of the program such as macros, types, or function prototypes change later in a way that would cause the unexecuted code to contain syntax errors, the unexecuted code must be brought up to date to correct the problem. Then, if it is needed again in the future, all that must be done is to remove the surrounding if statement and the NOTREACHED comment.
The NOTREACHED comment tells some compilers and static analysis tools not to complain about this unreachable code. It also serves as documentation.
| Code Block | ||
|---|---|---|
| ||
if (0) { /* use of critical security function no longer necessary, atfor leastnow for*/
now /*NOTREACHED*/
security_critical_function();
/* some other comment */
}
|
This is an instance of exception MSC07-EX1 to MSC07-A. Detect and remove dead code.
Non-Compliant Code Example
...