我摘出了标准(ISO/IEC 9899:1999 (E))中相当多的与这个问题有关的部分的,应该是足以回答本问题了。
大家可以感受一下,标准是怎么从一种客观的(就是不从实现的)角度描述 C 语言的。
和问题比较相关的主要是 6.7的5 和 6.9的5,前者指出什么样的声明是定义,后者指出定义最多不能超过一个。
6.7的3 主要是说为什么在 main 里不能写两个 int i;
另外,大家可以试试,同样的程序用 g++ 编译会报语法错误。(虽然这点我比较意外吧,但是确实应该这样。)
6.2.2 Linkages of identifiers
2 In the set of translation units and libraries that constitutes an entire program, each
declaration of a particular identifier with external linkage denotes the same object or
function. Within one translation unit, each declaration of an identifier with internal
linkage denotes the same object or function. Each declaration of an identifier with no
linkage denotes a unique entity.
4 For an identifier declared with the storage-class specifier extern in a scope in which a
prior declaration of that identifier is visible, if the prior declaration specifies internal or
external linkage, the linkage of the identifier at the later declaration is the same as the
linkage specified at the prior declaration. If no prior declaration is visib, or if the prior
declaration specifies no linkage, then the identifier has external linkage.
5 ... If the declaration of an identifier for an object has file scope and no storage-class specifier,
its linkage is external.
6 The following identifiers have no linkage: ... a block scope identifier for an object declared without
the storage-class specifier extern.
6.7 Declarations
3 If an identifier has no linkage, there shall be no more than one declaration of the identifier
(in a declarator or type specifier) with the same scope and in the same name space, except
for tags as specified in 6.7.2.3.
4 All declarations in the same scope that refer to the same object or function shall specify
compatible types.
5 A declaration specifies the interpretation and attributes of a set of identifiers. A definition
of an identifier is a declaration for that identifier that:
— for an object, causes storage to be reserved for that object;
— for a function, includes the function body;
— for an enumeration constant or typedef name, is the (only) declaration of the
identifier.
6.9 External definitions
5 An external definition is an external declaration that is also a definition of a function
(other than an inline definition) or an object. If an identifier declared with external
linkage is used in an expression (other than as part of the operand of a sizeof operator
whose result is an integer constant), somewhere in the entire program there shall be
exactly one external definition for the identifier; otherwise, there shall be no more than
one.