program main implicit none type my_type integer, pointer :: my_size(:) !integer, allocatable :: my_size(:) ! F03 allows the use of allocatables inside derived data types end type my_type ! However do remember that: ! (1) Pointers start life undefined where as allocatables start life as unallocated ! (2) Pointers will leak memory if not explicitly deallocated. In particular deallocating ! a derived type will NOT deallocate any pointer components. Allocatable components ! automatically deallocate when out of scope ! (3) When you copy (i.e. assign) a derived type value that has a pointer component, you ! end up with a second pointer to the same memory. You don't end up with two copies ! of the data type(my_type), allocatable :: x(:) allocate(x(3)) allocate(x(1)%my_size(3)) allocate(x(2)%my_size(2)) allocate(x(3)%my_size(1)) print*, x(1)%my_size print*, x(2)%my_size print*, x(3)%my_size deallocate(x(3)%my_size, x(2)%my_size, x(1)%my_size) deallocate(x) end program main