Storage class specifiers
A storage class specifier is used to refine the declaration of
a variable, a function, and parameters. Storage classes determine
whether:
- The object has internal, external, or no linkage
- The object is to be stored in memory or in a register, if available
- The object receives the default initial value of 0 or an indeterminate default initial value
- The object can be referenced throughout a program or only within the function, block, or source file where the variable is defined
- The storage duration for the object is maintained throughout program runtime or only during the execution of the block where the object is defined
For a variable, its default storage duration, scope, and linkage
depend on where it is declared: whether inside or outside a block
statement or the body of a function. When these defaults are not satisfactory,
you can use a storage class specifier to explicitly set its storage
class. The storage class specifiers in C and C++ are:
- auto
- static
- extern
mutable- register
__thread
Beginning of C++0x only.
In C++0x, the keyword auto is no longer used as
a storage class specifier. Instead, it is used as a type specifier.
The compiler deduces the type of an auto variable
from the type of its initializer expression. For more information,
see The auto type specifier (C++0x).
The keyword extern was previously used as a storage
specifier or as part of a linkage specification. The C++0x standard
adds a third usage to use this keyword to specify explicit instantiation
declarations. For more information, see Explicit instantiation (C++ only).
End of C++0x only.
Related information