外部链接External Linkage

如果标识符的文件范围级别的第一个声明不使用 static 存储类说明符,则该对象具有外部链接。If the first declaration at file-scope level for an identifier does not use the static storage-class specifier, the object has external linkage.

如果函数标识符的声明没有 storage-class-specifier,则就像使用 storage-class-specifier extern 声明它一样准确确定其链接。If the declaration of an identifier for a function has no storage-class-specifier, its linkage is determined exactly as if it were declared with the storage-class-specifier extern. 如果对象标识符的声明具有文件范围但没有 storage-class-specifier,则其链接为外部的。If the declaration of an identifier for an object has file scope and no storage-class-specifier, its linkage is external.

具有外部链接的标识符的名称指定相同的函数或数据对象,这与具有外部连接的相同名称的任何其他声明一样。An identifier's name with external linkage designates the same function or data object as does any other declaration for the same name with external linkage. 这两个声明可以在同一个翻译单元中,也可以在不同的翻译单元中。The two declarations can be in the same translation unit or in different translation units. 如果该对象或函数还具有全局生存期,则该对象或函数由整个程序共享。If the object or function also has global lifetime, the object or function is shared by the entire program.

另请参阅See Also

使用 extern 指定链接Using extern to Specify Linkage