This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: routine call with allocatable argument


Salut Jean,

comp.lang.fortran usually is a much better place to ask questions
about the standard, but since you are here, well let's see...

> subroutine A(tab)
> real(kind=long),dimension(:),allocatable,intent(inout):: tab
>
> [...]
>
> subroutine B(tab)
> real(kind=long),dimension(:,:),allocatable,INTENT(INOUT)::tab
> integer :: nx, ny, i
> ? if (allocated(tab)) deallocate(tab)
> ? allocate(tab(nx,ny))
>
> ? do i=1,nx
> ? ? ? call A(tab(i,:))
> ? end do

I am definitely not a standards person, but let's think about the
implications if this were standard-conforming:
You would allow tab to be deallocated by A. In your example, tab is
passed to A by B as 1D-slice of a 2D allocatable array, moreover a
strided one. Allowing you to deallocate or even "reallocate" this to
another size would seriously open a can of worms, therefore any
self-respecting standard should not allow you to do that. What happens
with g95 if you try to reallocate tab in A to a different size?

Side note: Calling A(tab(i, :)) is suboptimal w.r.t to Fortran's
storage sequence - this looks like you came from the C world, where
this is the right thing to do. tab(:, i) is usually preferrable
because access is contiguous like this.

Cheers,
Dennis


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]