CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit for current CERN information.

next up previous
Next: Pointers as dynamic Up: Fortran 90 Tutorial: Previous: Pointer functions

Arrays of pointers

These do not exist as such: given

     TYPE(entry) :: rows(n)

     rows%next              ! illegal
would be such an object, but with an irregular storage pattern. For this reason they are not allowed. However, we can achieve the same effect by defining a derived data type with a pointer as its sole component:

     TYPE row
        REAL, POINTER :: r(:)
and then defining arrays of this data type:

     TYPE(row) :: s(n), t(n)
where the storage for the rows can be allocated by, for instance,

     DO i = 1, n
        ALLOCATE (t(i)%r(1:i)) ! Allocate row i of length i
     END DO
The array assignment

     s = t
is then equivalent to the pointer assignments

     s(i)%r => t(i)%r
for all components.

Janne Saarela
Tue May 16 13:43:26 METDST 1995