the document about intent
attribute说
If an actual argument is an array section with a vector subscript, it cannot be associated with a dummy array that is defined or redefined (has intent OUT or INOUT).
我应该如何理解描述?
是不是说明下面的代码是错误的?
subroutine sub(a)
real, intent(out) :: a(:)
end subroutine sub
real :: arr(3,4)
call sub(arr(1,:))
最佳答案
那很好,它是一个数组部分而不是一个向量下标。后者是您对下标使用秩为一的整数数组表达式的地方。扩展您的示例:
subroutine sub(a)
real, intent(out) :: a(:)
end subroutine sub
real :: arr(3,4)
call sub(arr(1,:)) ! Legal
call sub(arr(1,[ 1, 2, 4 ] ) ! Illegal
关于Fortran INTENT 属性,带有带向量下标的实参,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56105863/