Static Storage-Class Specifiers
The static storage-class specifiers, static and extern, can be applied to objects and functions. The following table shows where the keywords static and extern can and cannot be used.
Use of static and extern
Construct |
Can static be Used? |
Can extern be Used? |
---|---|---|
Function declarations within a block |
No |
Yes |
Formal arguments to a function |
No |
No |
Objects in a block |
Yes |
Yes |
Objects outside a block |
Yes |
Yes |
Functions |
Yes |
Yes |
Class member functions |
Yes |
No |
Class member data |
Yes |
No |
typedef names |
No |
No |
A name specified using the static keyword has internal linkage except for the static members of a class that have external linkage. That is, it is not visible outside the current translation unit. A name specified using the extern keyword has external linkage unless previously defined as having internal linkage. For more information about the visibility of names, see Scope and Program and Linkage.
备注
Functions that are declared as inline and that are not class member functions are given the same linkage characteristics as functions declared as static.
A class name whose declaration has not yet been encountered by the compiler can be used in an extern declaration. The name introduced with such a declaration cannot be used until the class declaration has been encountered.