When passing sections of arrays to subroutines in Fortran, e.g. f(a, b, c(2:5,4:6)) (all of them 2D arrays), does the program first make a temporary copy of c, and then pass it to the subroutine (as reference, pointer, etc), or is the whole thing dynamically handled?
I am trying to convert some Fortran code to C++, and I see calls to subroutines that have sections of arrays passed as arguments. To my knowledge, C++ doesn't allow this so I tried to circumvent this in C++ like this (mat2d = std::vector<std::vector<T>>):
f(mat2d &a, mat2d &b, mat2d *a, int rows, int rows, int offsetx, int offsety) {...}
and calling as:
f(a, b, c.data(), ...)
This works but it requires the size(s), and also offsets for the cases where I want to make a generic matrix multiplication (for example). So, if Fortran first makes a copy of c(2:5,4:6) to (say) a temp(4,3) array, then I can mimic that in C++: simply make a copy to a temporary, and then pass a reference of that temporary to the function, without rows/columns/offsets. But if not... I wouldn't mind hearing other people's thoughts.
Example subroutine:
subroutine f(A, B, C)
implicit none
real(kind(1d0)) :: A(2,2), B(2,2), C(2,2)
C = A*B
return
end f
If my words are bad, maybe a picture with the real code will do? The arrays are auxfour(4,4), aux44(4,4), and Gv(2,2).
And here is a call, with auxp(5) and the same Gv:
Full subroutine. Picture, not words.



matmul(), which is also of interest (for me). I also have something likex(1:2,:)=matmul(y,z(1:2,:)). But I'm interested for any case where a slice of array is passed on: is that a copy, or not?