An object declaration outside of a function is called an external declaration. Contrast this with an internal declaration, which is a declaration made inside a function or block; the declaration is internal to that function or block, and is visible only to that function or block. The compiler recognizes an internally declared identifier from the point of the declaration to the end of the block.
If an object's declaration has file scope and an initializer, the declaration is also an external definition for the object. A C program consists of a sequence of external definitions of objects and functions.
Any definition reserves storage for the entity being declared. For example:
float fvalue = 15.0; /* external definition */ main () { int ivalue = 15; /* internal definition */ }
External data declarations and external function definitions take the same form as any data or function declaration (see Chapter 5 for standard function declaration syntax), and must follow these rules:
extern
or static
(see Section 2.10). If it is unspecified, the default is the
extern
storage class, and linkage for the declared
object is external. The type specifier may also be omitted, in
which case the default type is int
. Note that the
storage-class-specifier, type-qualifier, and
type-specifier cannot all be omitted from a declaration.
auto
and
register
objects are not permitted. Internally
declared auto
and register
objects are
not automatically initialized and, if not explicitly initialized,
have the irrelevant value previously stored at their address. All
static
objects are automatically initialized to 0,
if not explicitly initialized.
int
appeared in the block containing the call.
For example:
void function1() { int a,b; x (a,b); }Here, the compiler will behave as if the declaration
extern
int x();
appeared within the function1
definition block.
The first declaration of an identifier in a compilation unit must
specify, explicitly or by the omission of the static
keyword, whether the identifier is internal or external. For each
object, there can be only one definition. Multiple declarations of
the same object may be made, as long as there are no conflicting or
duplicate definitions for the same object.
An external object may be defined with either an explicit
initialization or a tentative definition. A declaration
of an object with file scope, without an initializer, and with
a storage-class specifier other than static
is a
tentative definition. The compiler will treat a tentative definition
as the object's only definition unless a complete definition for the
object is found. As with all declarations, storage is not actually
allocated until the object is defined.
If a compilation unit contains more than one tentative definition for an object, and no external definition for the object, the compiler treats the definition as if there were a file scope declaration of the object with an initializer of zero, with composite type as of the end of the compilation unit. See Section 2.7 for a definition of composite type.
If the declaration of an object is a tentative definition and has internal linkage, the declared type must not be an incomplete type. See Section 2.9 for examples of tentative definitions.