Lundin is correct, that in this case extern
does not affect visibility of fido
in other source files. In your example code, it is used as a forward declaration.
Relevant part from C99 standard, section 6.2.2:
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 visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.
5) 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. If the declaration of an identifier for an object has file scope and no storage-class specifier,
its linkage is external
In C++, behavior would be different, because variables declared with const
are implicitly static
. In C++, you are required to declare the variable with extern
the first time, or other compilation units would not find it.
C++98 standard, section 3.5.3:
A name having namespace scope (3.3.5) has internal linkage if it is the name of
— an object, reference, function or function template that is explicitly declared static or,
— an object or reference that is explicitly declared const and neither explicitly declared extern nor previously declared to have external linkage;