gtpa2m0zApplication Programming

Storage for Static Variables

Static storage contains the static variables declared in a C language program. For ISO-C the static storage is unique to a load module, subsystem, and environment. There is only 1 static storage allocation for each load module in the same subsystem and environment per ECB. The storage block used for static storage is obtained by the DLM startup code or library startup code that requires it. When static storage is required, the static storage block for the load module is found if one exists or obtained through a call to the $GMNBC macro if one does not exist. This storage comes from the ECB heap.

When writable static variables are used in a function, static storage maintains the values of these variables. To handle the static storage in libraries, secondary linkage is employed when a function is run. The secondary LIBVEC is used to manage processing the writable static. The extra overhead of this processing can cause a performance loss.

In TARGET(TPF) a chain of working storage blocks is used to contain the storage needed for any static variables declared in the C source module. These blocks are known as static blocks and contain 1 or more static frames. Each static frame maps to a single TPF C program segment.

In standard C, once a static frame is allocated, it remains in existence until the ECB exits. The same is true for TARGET(TPF) except for the case where entdc is called. In TARGET(TPF), the static block is removed if the ECB called an entdc.

In general the static exception routine handles the process of allocating static blocks.

For more information about coding with static storage, see Static Storage Considerations.