Insure++ Reference - UNUSED_VAR
Insure++ has the ability to detect unused variables in your
code. Since these are not normally errors, but informative messages,
this category is disabled by default.
Two different sub-categories are distinguished
assigned
|
The variable is assigned a value but never used.
|
unused
|
The variable is never used
|
The following code assigns a value to the variable
max but never uses it.
1: /*
2: * File: unuasign.c
3: */
4: main()
5: {
6: int i, a[10];
7: int max;
8:
9: a[0] = 1;
10: a[1] = 1;
11: for(i=2; i<10; i++)
12: a[i] = a[i-1]+a[i-2];
13: max = a[9];
14: }
Normally this code will run without displaying any messages. If
UNUSED_VAR messages are enabled, however, the
following display will result.
1. [unuasign.c:7] **UNUSED_VAR(assigned)**
2. Variable assigned but never used: max
>> int max;
- Source line at which the problem was detected.
- Description of the error and the parameters used.
The following code never uses the variable max .
1: /*
2: * File: unuvar.c
3: */
4: main()
5: {
6: int i, a[10];
7: int max;
8:
9: a[0] = 1;
10: a[1] = 1;
11: for(i=2; i<10; i++)
12: a[i] = a[i-1]+a[i-2];
13: }
If UNUSED_VAR messages are enabled, however, the
following display will result.
1. [unuvar.c:7] **UNUSED_VAR(unused)**
2. Variable declared but never used: max
>> int max;
- Source line at which the problem was detected.
- Description of the error and the parameters used.
These messages are normally suppressed but can be enabled by adding
the option
insure++.unsuppress UNUSED_VAR
to your .psrc file.
You can also enable each sub-category independently with an option
such as
insure++.unsuppress UNUSED_VAR(assigned)
In most cases, the corrective action to be taken is to remove the
offending statement, since it is not affecting the behavior of the
application. In certain circumstances, these errors may denote logical
program errors in which a variable should have been used but wasn't.
RETURN_INCONSISTENT
USER_ERROR
|