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 the following listing for an example of declarations that prevent the compiler from applying program-level analysis.

Listing: 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 */

The following listing fixes this problem by renaming the conflicting symbols.

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