Type Definitions

Because the compiler examines all source files for a program, make sure all definitions for a type are the same. See Type definitions conflicts in program-level interprocedural analysis for an example of conflicting type definitions. Fixing type definitions conflicts in C and Fixing type definitions conflicts in C++ show suggested solutions.

Listing 1. Type definitions conflicts in program-level interprocedural analysis
/* fileA.c */
struct a_rec { int i, j; };
a_rec a;

/* fileB.c */
struct a_rec { char c; }; /* Conflict with a_rec in fileA.c */
a_rec b;
Listing 2. Fixing type definitions conflicts in C
/* fileA.c */
struct a1_rec { int i, j; };
a1_rec a;

/* fileB.c */
struct a2_rec { char c; };
a2_rec b;
Listing 3. Fixing type definitions conflicts in C++
/* fileA.c */
namespace { struct a_rec { int i, j; }; }
a_rec a;

/* fileB.c */
namespace { struct a_rec { char c; }; }
a_rec b;