INTENT with POINTER formal parameters
Angelo Graziosi
angelo.graziosi@alice.it
Thu Jun 13 13:07:00 GMT 2013
Il 13/06/2013 15.04, Angelo Graziosi ha scritto:
> On Cygwin, both gcc-4.5.3 and gcc-4.9 snapshot (my build) accept this code
>
> module foo
> implicit none
>
> real, pointer :: arr(:,:)
>
> contains
> subroutine sub(a,dim)
> implicit none
> real, pointer, intent(in) :: a(:,:)
> integer, intent(in) :: dim
> integer :: i,j
> do i = -3,dim
> do j = -2,dim
> print *, 'A(',i,',',j,')',a(i,j)
> end do
> end do
> end subroutine sub
> end module foo
>
> program array_test
> use foo
> implicit none
> integer :: ierr,n
>
> print *, 'N : '
> read *,n
>
> allocate(arr(-3:n,-2:n),stat=ierr)
> if (ierr /= 0) then
> print *, '*** FATAL ERROR ***'
> print *, 'ARR: Allocation request denied'
> stop
> end if
>
> arr = 1.
> call sub (arr,n)
>
> deallocate(arr,stat=ierr)
> if (ierr /= 0) then
> print *, '*** FATAL ERROR ***'
> print *, 'ARR: Deallocation request denied'
> stop
> end if
> end program array_test
>
> As you see the routine "sub" declare the formal parameter "a" as
>
> real, pointer, intent(in) :: a(:,:)
>
> i.e. it uses INTENT with the pointer variable. Now on a Fortran book I read
oops..
SUBROUTINE readin(iounit,z)
INTEGER, INTENT(IN) :: iounit
REAL, POINTER :: z(:) ! NB: INTENT not allowed here with POINTER
>
> So which is true? Perhaps that was valid only with F90/95 and F2003/2008
> allow it, now...
>
>
> TIA,
> Angelo.
More information about the Fortran
mailing list