Only actual instances of variables or derived types may have the TARGET
attribute. So, the allocatable in the second type definition cannot be a target as this is just a description of what the type should look like, a template if you like.
However, you can give a real instance of the type the TARGET
attribute and then point to any of it's component parts with appropriately declared Fortran pointers.
Editted: An alternative, and probably more what you're after, is to give the vector array in the type the POINTER
attribute only, which implicitly makes it both legitimate pointee and may be used to allocate memory. You just have to make sure that you don't reassign the pointer (v
in example below) after you've used it to allocate the memory, because then you'll have a leak.
PROGRAM so_pointtype
IMPLICIT NONE
TYPE vec
INTEGER :: x = 2, y = 3
END TYPE vec
TYPE foo
TYPE(vec),POINTER :: v(:)
END TYPE foo
TYPE(foo) :: z
TYPE(vec),DIMENSION(:),POINTER :: p2 => NULL()
ALLOCATE(z%v(3))
PRINT*,z%v(:)
p2 => z%v(:)
PRINT*,p2
END PROGRAM so_pointtype