title: Passing scalars and array elements to a procedure expecting an array
body: <p>I have some legacy Fortran 77 code which I'm trying to at least compile without warnings (without disabling warnings). There are subroutine calls that pass a scalar where subroutine expects an array, since the scalar is used as a size-1 array, this causes no problems. But with the Intel compiler, if I enable interface warnings I get this <em>error</em>:</p>
  
  <pre><code>error #8284: If the actual argument is scalar, the dummy argument shall be scalar unless the actual argument is of type character or is an element of an array that is not assumed shape, pointer, or polymorphic.
  </code></pre>
  
  <p>In some cases, I've tried to solve this by overloading the subroutine with array and scalar variants, but then I face a problem when the argument passed is an "an element of an array", which is detected as a scalar. Consider the following sample (tested with gfortran):</p>
  
  <pre><code>program a
    integer n,dum(3)
    interface readn
      subroutine readn_s(n,m)
        integer m,n
      end subroutine
      subroutine readn_a(n,m)
        integer m,n(*)
      end subroutine
    end interface
    call readn(n,1)
    write(6,*) 'n=',n
    call readn(dum,3)
    write(6,*) 'dum=',dum
    call readn(dum(2),2)
    write(6,*) 'dum=',dum
  end program
  
  subroutine readn_s(n,m)
    integer i,m,n
    n=2
  end subroutine
  
  subroutine readn_a(n,m)
    integer i,m,n(*)
    do i=1,m
      n(i)=1
    end do
  end subroutine
  </code></pre>
  
  <p>The <code>readn(dum,3)</code> call correctly uses <code>readn_a</code>, while the second one uses <code>readn_s</code>. The intended behaviour is that both should use <code>readn_a</code>. Indeed, if I replace both calls with <code>readn_a</code> everything is as expected.</p>
  
  <p>Is it possible to have this working properly and use the "array" version of the overloaded routine when the actual argument is an array element? I've found out it works if I call the subroutine with <code>readn(dum(2:),2)</code>, but I'm afraid that creates a temporary copy of the array...</p>
  
  <h2>Original problem:</h2>
  
  <p>file.f90</p>
  
  <pre><code>program a
    integer n,dum(3)
    call readn_a(n,1)
    write(6,*) 'n=',n
    call readn_a(dum,3)
    write(6,*) 'dum=',dum
    dum=3
    call readn_a(dum(2),2)
    write(6,*) 'dum=',dum
  end program
  </code></pre>
  
  <p>file2.f90</p>
  
  <pre><code>subroutine readn_a(n,m)
    integer i,m,n(*)
    do i=1,m
      n(i)=1
    end do
  end subroutine
  </code></pre>
  
  <p>Compile with <code>gfortran -Wall file.f90 file2.f90</code> or <code>ifort file.f90 file2.f90</code>, all is fine and the output is the intended:</p>
  
  <pre><code> n=           1
   dum=           1           1           1
   dum=           3           1           1
  </code></pre>
  
  <p>Compile with <code>ifort -warn all file.f90 file2.f90</code> and I get the <code>error #8284</code> above. So that's why I wanted a version of the subroutine that would work with scalars or arrays... but would give the array version with an array element.</p>