This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
INTENT with POINTER formal parameters
- From: Angelo Graziosi <angelo dot graziosi at alice dot it>
- To: fortran <fortran at gcc dot gnu dot org>
- Date: Thu, 13 Jun 2013 15:04:32 +0200
- Subject: INTENT with POINTER formal parameters
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
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.