In this section:
Overview
This error is generated when code is not evaluated, has no effect, or is unreachable. Insure++ distinguishes between several types of dead code: Code is not evaluated, has no effect, or is unreachable Compilation Code Description Enabled Reported Platform DEAD_CODE Windows/Unix (emptyloopbody) Loop body is empty. Compilation Windows/Unix (emptystmt) The statement is empty. Compilation Windows/Unix (noeffect) Code has no effect. Compilation Windows/Unix (notevaluated) Code is not evaluated. Compilation Windows/Unix
Problem
The following code has several types of DEAD_CODE errors in C.
/*
* File: deadcode.c
*/
int main()
{
int i = 0;
;
i;
for (i; i; i)
;
return 0;
}
Diagnosis During Compilation
[deadcode.c:9] **DEAD_CODE(noeffect)** Expression has no effect. >> i; [deadcode.c:10] **DEAD_CODE(noeffect)** Expression has no effect. >> for (i; i; i) [deadcode.c:10] **DEAD_CODE(noeffect)** Expression has no effect. >> for (i; i; i)
- Line 1: Source line at which the problem was detected.
- Line 2: Description of the problem and the expression that is incorrect.
- Line 6: Initializer in for-loop does nothing.
- Line 9: Increment expression in for-loop does nothing.
Repair
These errors are usually corrected by removing the superfluous statement or by modifying the statement so that it does what it was intended to do, e.g., add a missing increment operator. An empty loop body may be useful in certain situations. In such a case, you may want to suppress that subcategory of DEAD_CODE.