next up previous contents
Next: Example: Linked Lists Up: Pointers and Targets Previous: Pointer Valued Functions   Contents

Pointers and Derived Types

F90 allows pointers to derived types

type(DP_Complex), target :: a 
type(DP_Complex), pointer :: Ptr_a  
Ptr_a => a

Derived types may contain pointer components

type Student  
 integer :: id  
 character,dimension(:),pointer :: name  
end type Student
When the derived type contains pointer components, the structure asignment works as follows. Consider the code sequence
type(Student) :: stud1, stud2  
stud1 = stud2
The meaning is that
stud1%id = stud2%id      ! copy  
stud1%name => stud2%name ! pointer assignment
Although it is not possible to have ALLOCATABLE arrays as components of derived types, we can still work with student names of different lengths using pointer components. Here the component name is a pointer to a dynamically sized 1-D array of characters. We use it as follows:
type(Student) :: leader  
leader%id = 1234
allocate(leader%name(8))  
leader%name = (/"J","o","h","n"," ","D","o","e"/) 



Adrian Sandu 2001-08-26