Type Definitions

Because the compiler examines all source files for a program, make sure all definitions for a type are the same. See the following listing for an example of conflicting type definitions.

Listing: 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;

The following listing shows a suggested solution.

Listing: 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;

The following listing shows another suggested solution.

Listing: 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;