Fortran INTENT 属性,带有带向量下标的实参
Fortran INTENT attribute with an actual argument with vector subscript
Intel's documentation about the 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
Intel's documentation about the 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