Section 6.11.2 of the C standard states one of the features that may be deprecated in future versions:
Declaring an identifier with internal linkage at file scope without the static storage-class specifier is an obsolescent feature.
How is it even possible to declare a file scope identifier to have internal linkage without the static storage-class specifier?
To use internal linkage we have to use which keyword? Explanation: static keyword is used for internal linkage.
The scope of a global variable can be restricted to the file containing its declaration by prefixing the declaration with the keyword static . Such variables are said to have internal linkage.
Both are decided by linkage. Linkage thus allows you to couple names together on a per file basis, scope determines visibility of those names. There are 2 types of linkage: Internal Linkage: An identifier implementing internal linkage is not accessible outside the translation unit it is declared in.
Explanation: External Linkage-> means global, non-static variables and functions. Internal Linkage-> means static variables and functions with file scope. None Linkage-> means Local variables.
There is a specific example for this issue in the C++ standard. In [dcl.stc]:
static int b; // b has internal linkage
extern int b; // b still has internal linkage
So in the second line, b is declared as a file scope identifier with internal linkage without the keyword static. The example is also true for C, as C11:6.2.2 says:
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.
see this question for more detail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With