CS 3733 Operating Systems Notes: Storage and Linkage Classes


This material is from Chapter 2 of PUP.

Storage classes: static and automatic

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.


Object Where Declared static Modifies static
Applied?
Storage
Class
Linkage
Class
variableinside a function storage class yes static none
variable inside a function storage class no automatic none
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   internal
function outside any function linkage class no   external

Table 2.1 (page 31, modified): Effect of using the static keyword modifier in a C program.


Example: Assume that the following are in a file called bubblesort.c
Give the storage class and linkage class of each of the variables and functions in the following program.
static int count = 0;

static int onepass(int a[], int n) { /* return true if interchanges are made */

   int i;
   int interchanges = 0;
   int temp;

   for (i = 0; i < n - 1; i++)
      if (a[i] > a[i+1]) {
         temp = a[i];
         a[i] = a[i+1];
         a[i+1] = temp;
         interchanges = 1;
         count++;
      }
   return interchanges;
}

void clearcount( ) {
   count = 0;
}

int getcount( ) {
   return count;
}

void bubblesort(int a[], int n) { /* sort a in ascending order */
   int i;
   for (i = 0; i < n - 1; i++)
      if (!onepass(a, n - i))
         break;
}