0

Why does the following code not yield a mismatch error when we call the MakeAllZero subroutine? The variable array is initialised as a 3x3 array, but once we call the subroutine a do loop travels from index 1 to 9 where I would expect a mismatch error.

I do not understand the trick done by the assumed-size array declaration in the subroutine. I would appreciate if anyone could help me better understand it.

program main
    implicit none

    real, dimension(3, 3) :: array
    
    array = reshape([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 ], shape(array))

    call MakeAllZero(array,9)

    print*, array
end program main

subroutine MakeAllZero(R,K)
    implicit real (A-H,O-Z)
    dimension R(*)
    
    do J=1,K
        R(J) = 0.0
    end do

    return
end subroutine MakeAllZero
  • 1
    The code doesn't yield a mismatch error, because there's no mismatch. A rank-1 _assumed size_ dummy argument can be associated with a rank-2 actual actual argument. Inside `MakeAllZero` the dummy is rank-1, so accepts only one index. On top of "assumed size", also include the term "sequence association" in your further research. – francescalus Jul 31 '23 at 13:40

0 Answers0