Quick facts

Add-on Modules:


Technical Papers

Support & Manuals


Recent Reviews

User Testimonials

Press Releases

Insure tool to debug c++

Insure++ Reference - BAD_DECL


Global declarations are inconsistent

This error is generated whenever Insure++ detects that a variable has been declared as two different types in distinct source files. This can happen when there are two conflicting definitions of an object or when an extern reference to an object uses a different type than its definition.

In any case, Insure++ proceeds as though the variable definition is correct, overriding the extern reference.


In the following example, the file baddecl1.c declares the variable a to be a pointer, while the file baddecl2.c declares it to be an array type.

	1:	/*
	2:	 * File: baddecl1.c
	3: 	 */
	4:	int *a; bug

Figure 1. baddecl1.C code

	1: 	/*
	2:	 * File: baddecl2.c
	3:	 */
	4:	extern int a[]; bug
	6:	main()
	7:	{
	8:		a[0] = 10;
	9:		return (0);
	10:	}

Figure 2. baddecl2.C code

Diagnosis (at runtime)

	[baddecl2.c:4] **BAD_DECL**
1.	>> 		extern int a[];

2.		Incompatible global declarations: a

3.		Array and non-array declarations are not equivalent.
		Actual declaration:
			non-array (4 bytes), declared at baddecl1.c, 4
4.		Conflicting declaration:
			array of unspecified size, 
					declared at baddecl2.c, 4

  1. Source-line at which the problem was detected.
  2. Description of the problem and the object whose declarations conflict.
  3. Brief description of the conflict.
  4. Information about the conflicting definitions, including the sizes of the declared objects and the locations of their declarations.


The lines on which the conflicting declarations are made are both shown in the diagnostic report. They should be examined and the conflict resolved.

In the case shown here, for example, a suitable correction would be to change the declaration file to declare an array with a fixed size, e.g.,

	baddecl1.c, 4: int a[10];

An alternative correction would be to change the definition in baddecl2.c to indicate a pointer variable, e.g.,

	baddecl2.c, 4: extern int *a;

Note that this change on its own will not fix the problem. In fact, if you ran the program modified this way, you would get another error, EXPR_NULL, because the pointer, a, doesn't actually point to anything and is NULL by virtue of being a global variable, initialized to zero.

To make this version of the code correct, you would need to include something to allocate memory and store the pointer in a, e.g.,

	1:  /*
        2:   * File: baddecl2.c (modified)
	3:   */
	4:  #include <stdlib.h>
	5:  extern int *a;
	7:  main()
	8:  {
	9:    a = (char *)malloc(10*sizeof(int));
	10:    a[0] = 10;
	11:  }

Some applications may genuinely need to declare objects with different sizes, in which case you can suppress error messages by inserting the line

	insure++.suppress BAD_DECL

into your .psrc file.

Tools to debug c++ and java
(888) 305-0041 Copyright © 1996-2001 ParaSoft