next up previous contents
Next: Example: Sorting Vectors Up: Pointers and Targets Previous: Example: Linked Lists   Contents

Arrays of Pointers

Despite the F90 syntax restrictions, it is possible to create de facto arrays of pointers. For example, the sequence

type iptr  
 integer, pointer :: comp  
end type iptr  
type(iptr), dimension(100) :: I
declares a 100 dimensional vector whose components are pointers to integers. It is not possible to select sections of the I array
I(10)%comp    ! valid  
I(10:20)%comp ! invalid  
We can define an array of pointers to integer arrays
type IAptr  
 integer, dimension(:), pointer :: comp  
end type Iptr  
type(IAptr), dimension(100) :: IA
Each pointer component can then be made to point to an unnamed space in the heap,
allocate(IA(1)%comp(20), STAT=ierr) 
or can be made to point to an existing array
integer, target :: JA(10)  
ia(2)%comp => JA 

Note that ALLOCATABLE arrays cannot be components of derived types.

Adrian Sandu 2001-08-26