CS 3733 Operating Systems Notes: Storage and Linkage Classes
This material is from Chapter 2 of PUP.
Storage classes: static and automatic
- static storage class refers to variables that, once allocated, persist
throughout the execution of a program.
-
automatic storage class refers to variables which come into existence when the
block in which they are declared is enteredand are discarded when the defining
block is exited.
- Variables declared inside a function have automatic storage class unless
they are declared to be static.
These are usually allocated on the program stack.
-
Variables defined outside any funtions have static storage class.
The word static has two meanings is C.
One is related to storage class and the other to linkage class.
Linkage class determines whether variables can be accessed in files other than
the one in which they are declared.
- Internal linkage class means they can only be accessed in the file in which
they are declared.
- External linkage class means they can be accessed in other files.
- variables decalred outside and function and function name identifiers have
external linkage by default.
They can be given internal linkage with the key word static.
-
Varibales decalred inside a function are only known inside that function and
so have internal linkage.
Object |
Where Declared |
static Modifies |
static Applied? |
Storage Class |
Linkage Class |
variable | inside a function | storage class | yes | static | internal |
variable |
inside a function |
storage class |
no |
automatic |
internal |
variable |
outside any function |
linkage class |
yes |
static |
internal |
variable |
outside any function |
linkage class |
no |
static |
external |
function |
outside any function |
linkage class |
yes |
static |
internal |
function |
outside any function |
linkage class |
no |
static |
external |
Table 2.1 (page 31):
Effect of using the static keyword modifier in a C program.