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. |
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.
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.
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 |
name |
is the name of the routine to be generated. |
The following are some limitations that you should be aware of when using the dynamic common option:
If you use the technique of implementing your own allocation routine, then you should specify only one dynamic COMMON block on the command line. Otherwise, you may not know the name of the COMMON block for which you are allocating storage.
An entity in a dynamic COMMON may not be initialized in a DATA statement.
Only named COMMON blocks may be designated as dynamic COMMON.
An entity in a dynamic COMMON must not be used in an EQUIVALENCE expression with an entity in a static COMMON or a DATA-initialized variable.