extern

The extern storage class specifier lets you declare objects and functions that several source files can use. All object declarations that occur outside a function and that do not contain a storage class specifier declare identifiers with external linkage. All function definitions that do not specify a storage class define functions with external linkage.

An extern variable, function definition, or declaration also makes the described variable or function usable by the succeeding part of the current source file. This declaration does not replace the definition. The declaration is used to describe the variable that is externally defined.

If a declaration for an identifier already exists at file scope, any extern declaration of the same identifier found within a block refers to that same object. If no other declaration for the identifier exists at file scope, the identifier has external linkage.

An extern declaration can appear outside a function or at the beginning of a block. If the declaration describes a function or appears outside a function and describes an object with external linkage, the keyword extern is optional.

If you do not specify a storage class specifier, the function has external linkage.

In C++, an extern declaration cannot appear in class scope.

Initialization
You can initialize any object with the extern storage class specifier at file scope. You can initialize an extern object with an initializer that must either:

If you do not explicitly initialize an extern variable, its initial value is zero of the appropriate type. Initialization of an extern object is completed by the time the program starts running.

Storage
Storage is allocated at compile time for extern variables that are initialized. Uninitialized variables are mapped at compile time and initialized to 0 (zero) at load time. This storage is freed when the program finishes running.



Constant Expressions
File Scope Data Declarations


Function Declarations