12.3.6 Static Storage Allocation

Because FORTRAN typifies the issues for static storage allocation, it will be used as the example here. For FORTRAN and other languages which allow static storage allocation, the amount of storage required to hold each variable is fixed at translation time.

Such languages have no nested procedures or recursion and thus only one instance of each name (the same identifier may be used in different context, however).

In FORTRAN each procedure or function, as well as the main program and a few other program structures not discussed here, may be compiled separately and associated with an activation record that can be entirely allocated by the compiler.

Example 1 shows the skeleton of a FORTRAN program and its storage allocation.

EXAMPLE 1 Static storage example

For each program unit such as the main program, a function or a subroutine (procedure), there is a code segment and an activation record. Figure 1 is a picture of what the run-time system might look like for the program skeleton of Example 1:

Figure 2 shows X's offset within the activation record:

Notice that everything except the beginning of the allocated storage is known at compile-time: the position (offset) of the activation record within the data area and even X's position (offset) within the activation record for its unit. The only decision to be made at run-time (and often made by the system linker) is where to put the entire data structure.

In static storage allocation, variables are also said to be static because their offset in the run-time system structure can be completely determined at compile time.

Send questions and comments to: Karen Lemone