The
extern keyword has already
been briefly described and demonstrated. It tells the compiler that a variable
or a function exists, even if the compiler hasn’t yet seen it in the file
currently being compiled. This variable or function may be defined in another
file or further down in the current file. As an example of the
latter:
When the compiler encounters the
declaration ‘extern int i’, it knows that the definition for
i must exist somewhere as a global variable. When the compiler reaches
the definition of i, no other declaration is visible, so it knows it has
found the same i declared earlier in the file. If you were to define
i as static, you would be telling the compiler that i is
defined globally (via the extern), but it also has file
scope (via the static), so the compiler will
generate an error.