I've heard there are differences between languages about the meaning of the keyword static
, but I've not found a good list that consolidates those differences.
Here's what I know about the meaning of static
in C++:
- For local static variables within a function, the variable is initialized at startup and the value is saved across function calls.
- Static data members are shared among all instances of a class. In other words, there is only one instance of a static data member. Static data members must be initialized at file scope.
- Static member functions have access only to static members.
- In recursive code, a static object or variable is guaranteed to have the same state in different instances of a block of code.
- Static objects and variables defined at file scope only have internal linkage. No other files may use them.
How does the meaning of static
change in other languages?