ALLOCATE statement

Standard: F77 F90 F95 F2003 F2008 Example program


ALLOCATE ( [ type-spec :: ] item-list [ , alloc-opt ]... )

item-list ::= item [ , item ]...
item ::= variable [ ( shape ) ]
shape ::= bounds [ , bounds ]...

alloc-opt ::= ERRMSG = variable
| MOLD = expression
| SOURCE = expression
| STAT = variable

Each item must have the ALLOCATABLE or POINTER attribute. If an item is an array, it must be followed by a shape with the same number of bounds as the rank of the item,

The ERRMSG= variable must be a scalar character variable of default kind. The STAT= variable must be a scalar integer variable, and should be at least 16 bits in size.

SOURCE= and type-spec are mutually exclusive.


Allocates memory for a list of pointers and allocatable variables. If an item is allocatable, it must not be currently allocated (or an error will occur).

The shape is required for each item that is an array, with the same number of bounds as the rank of the array, unless the MOLD= or SOURCE= clause appears with an array expression. If the lower bound expression is omitted, the lower bound will be 1.

If an error occurs, e.g. an allocatable item is already allocated or there is not enough memory available, the program will be terminated unless the STAT= clause is present. The STAT= variable is set to zero if all allocations succeed, or to an error code if one of them fails.

In Fortran 2003, there are several additions.

In Fortran 2008, there are more additions.


ALLOCATABLE attribute, ALLOCATED intrinsic function, ASSOCIATED intrinsic function, DEALLOCATE statement, ERRMSG= specifier, LBOUND intrinsic function, MOLD= specifier, MOVE_ALLOC intrinsic subroutine, POINTER attribute, SHAPE intrinsic function, SIZE intrinsic function, SOURCE= specifier, STAT= specifier, UBOUND intrinsic function