In Fortran, slices an array to create a copy in memory?

Let's say I pass a slice of an array into a routine that manipulates its inputs:

some_subroutine(a(:,1))

Is the length of the source text modified aor is some copy a(:,1)modified?

+4
source share
2 answers

There are several other answers that may touch on slightly different (but relevant) points. Here I will try to coordinate them.

Vladimir F answer examines the so-called copy / copy mechanism; bfletch answer the final effect of the argument.

In general, the effect of the following

integer i(2,2)
i=0
call dosomething(i(1,:))   ! Just to make it not contiguous.

contains
  subroutine dosomething(j)
    integer j(2)  ! or j(*), or j(:)
    j=1
  end subroutine
end program

, i , 1, 0. , : , ( ), , , .

, : value. 1

subroutine doseomthing(j)
  integer, value :: j(2)
  j=1
end subroutine

. j i.


1 Fortran. Fortran 90, , .

+5

, a some_subroutine.

, , , a , , a , .

a , , a(:,1) , , some_subroutine

subroutine some_sub(b)
  real :: some_sub(:)
+4

Source: https://habr.com/ru/post/1662755/


All Articles