Function and Top-level Variable Declarations

Because the compiler treats all files that compose a program as if they were a single, large source file, you must make sure all non-static declarations for variables or functions with the same name are identical. See Declaration conflicts in program-level interprocedural analysis for an example of declarations that prevent the compiler from applying program-level analysis. Fixing declaration conflicts for program-level interprocedural analysis fixes this problem by renaming the conflicting symbols.

Listing 1. Declaration conflicts in program-level interprocedural analysis
/* file1.c */
extern int i;
extern int f();
int main(void)
{
   return i + f();
}

/* file2.c */
short i;       /* Conflict with variable i in file1.c. */
extern void f(); /* Conflict with function f() in file1.c */
Listing 2. Fixing declaration conflicts for program-level interprocedural analysis
/* file1.c */
extern int i1;
extern int f1();
int main(void)
{
   return i1 + f1();
}

/* file2.c */
short i2;       
extern void f2();