Hello,
I am trying to do some C-like hacks that rely on sequence association using
pointers, and I am finding that the standard is more strict about
assumed-size arrays than I thought. Can someone please point to my why the
attached simple code causes a compilation error on the line with the three
exclamation points?
Thanks,
Aleksandar
_____________________________________________
Aleksandar Donev
http://www.pa.msu.edu/~donev/
[log in to unmask]
(517) 432-6770
Department of Physics and Astronomy
Michigan State University
East Lansing, MI 48824-1116
_____________________________________________
program test
implicit none
type one
integer :: key
end type one
type(one), dimension(:), allocatable, target :: ones
type(one), pointer :: one_pointer
integer :: i
allocate(ones(10))
do i=1,10
ones(i)%key=i
end do
one_pointer=>ones(3)
call print_ones(ones(3), 3) ! This compiles just fine
! call print_ones(one_pointer, 3) ! -- THIS CAUSES AN ERROR !!! WHY ?
contains
subroutine print_ones(ones, n)
type(one), dimension(*), intent(inout) :: ones
integer, intent(in) :: n
integer :: i
do i=1, n
write(*,*) "Key:", ones(i)%key
end do
end subroutine print_ones
end program test
|