Common Block

The following two options are used for the common blocks:

-Qdyncom"blk1,blk2 ..."

Dynamically allocates COMMON blocks at runtime. See section Dynamic Common Option that follows.

-Qloccom"blk1,blk2, ..."

Enables local allocation of given COMMON blocks at run time. See Allocating Memory to Dynamic COMMON Blocks.

Dynamic Common Option

The -Qdyncom option dynamically allocates COMMON blocks at runtime. This option on the compiler command line designates a COMMON block to be dynamic, and the space for its data is allocated at runtime, rather than compile time. On entry to each routine containing a declaration of the dynamic COMMON block, a check is made of whether space for the COMMON block has been allocated. If the dynamic COMMON block is not yet allocated, space is allocated at the check time.

The following example of a command-line specifies the dynamic common option with the names of the COMMON blocks to be allocated dynamically at runtime:

IA-32 applications:

prompt>ifc -Qdyncom"BLK1,BLK2,BLK3" test.f

Itanium-based applications:

prompt>efc -Qdyncom"BLK1,BLK2,BLK3" test.f

where BLK1, BLK2, and BLK3 are the names of the COMMON blocks to be made dynamic.

Allocating Memory to Dynamic Common Blocks

The runtime library routine, f90_dyncom, performs memory allocation. The compiler calls this routine at the beginning of each routine in a program that contains a dynamic COMMON block. In turn, this library routine calls _FTN _ALLOC() to allocate memory. By default, the compiler passes the size in bytes of the COMMON block as declared in each routine to f90_dyncom, and then on to _FTN_ALLOC(). If you use the nonstandard extension having the COMMON block of the same name declared with different sizes in different routines, you may get a runtime error depending upon the order in which the routines containing the COMMON block declarations are invoked.

The runtime library contains a default version of _FTN_ALLOC(), which simply allocates the requested number of bytes and returns.

Why Use a Dynamic Common

One of the primary reasons for using dynamic COMMON is to enable you to control the COMMON block allocation by supplying your own allocation routine. To use your own allocation routine, you should link it ahead of the runtime library routine. This routine must be written in the C language to generate the correct routine name.

The routine prototype is as follows:

void _FTN_ALLOC(void *mem, int *size, char *name);

where

mem

is the location of the base pointer of the COMMON block which must be set by the routine to point to the block memory allocated.

size

is the integer number of bytes of memory that the compiler has determined are necessary to allocate for the COMMON block as it was declared in the program. You can ignore this value and use whatever value is necessary for your purpose.

Note
You must return the size in bytes of the space you allocate. The library routine that calls _FTN _ALLOC() ensures that all other occurrences of this common block fit in the space you allocated. Return the size in bytes of the space you allocate by modifying the size parameter.

name

is the name of the routine to be generated.

Rules of Using Dynamic Common Option

The following are some limitations that you should be aware of when using the dynamic common option: