ALLOCATABLE (Fortran 2003)

Purpose

The ALLOCATABLE attribute allows you to declare an allocatable object. You can dynamically allocate the storage space of these objects by executing an ALLOCATE statement or by a derived-type assignment statement. If the object is an array, it is a deferred-shape array or an assumed-rank array.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-ALLOCATABLE--+----+------------------------------------------>
                '-::-'   

   .-,---------------------------------------------------.   
   V                                                     |   
>----object_name--+------------------------------------+-+-----><
                  '-+-(--deferred_shape_spec_list--)-+-'     
                    '-assumed_rank_spec--------------'       

object_name
The name of an allocatable object.
deferred_shape_spec
A colon, where each colon represents a dimension.
assumed_rank_spec
Two periods. For more information, see Assumed_rank_spec.

Rules

The object must not be a pointee.

If the object is an array specified elsewhere in the scoping unit with the DIMENSION attribute, the array specification must be a deferred_shape_spec or an assumed_rank_spec.

You can initialize an allocatable object after the storage space is allocated. If you compile your program with -qinitalloc, all uninitialized allocated objects are initialized.

Table 1. Attributes compatible with the ALLOCATABLE attribute
ASYNCHRONOUS OPTIONAL SAVE
AUTOMATIC  2  PRIVATE STATIC  2 
DIMENSION PROTECTED  1  TARGET
INTENT PUBLIC VOLATILE
Note:
  •  1  Fortran 2003
  •  2  IBM extension

Examples

! Two-dimensional array a declared but no space yet allocated
REAL, ALLOCATABLE :: a(:, :)  
READ (5, *) i, j
ALLOCATE(a(i, j))


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us