Search code examples
fortranintel-fortran

Fortran INTENT attribute with an actual argument with vector subscript


Intel's documentation about the intent attribute says

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).

How should I understand the description?

Does it mean that the following code is wrong?

subroutine sub(a)
    real, intent(out) :: a(:)
end subroutine sub

real :: arr(3,4)
call sub(arr(1,:))

Solution

  • That is fine, it is an array section rather than a vector subscript. The latter is where you use a rank one integer array expression for the subscripts. Extending your example:

    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