Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Insure++

Quick facts

Add-on Modules:
   -INUSE
   -TCA

Comparisons

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases


Insure tool to debug c++





Insure++ Reference - UNUSED_VAR



UNUSED_VAR

Unused variables

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

Problem #1

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]; bug
	14:	}

Diagnosis (during compilation)

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;
  1. Source line at which the problem was detected.
  2. Description of the error and the parameters used.

Problem #2

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; bug
	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:	}

Diagnosis (during compilation)

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;
  1. Source line at which the problem was detected.
  2. Description of the error and the parameters used.

Repair

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
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft