title: passing pointer arguments in fortran
body: <p>I am wondering what is the proper way to write the following code?</p>
  
  <pre><code>PROGRAM foo
  
    INTEGER :: x
    REAL(KIND=8), TARGET, DIMENSION(0: 10) :: array
    REAL(KIND=8), POINTER, DIMENSION(:) :: ptr
  
    ptr =&gt; array
  
    CALL bar(ptr)
  
  END PROGRAM foo
  
  SUBROUTINE bar (ptr)
  
    REAL(KIND=8), POINTER, DIMENSION(:) :: ptr                                                                                                                                                                                                                  
    INTEGER x
    DO x =0, 10
      ptr(x) = 2 // seg faults
    ENDDO
  
  END SUBROUTINE bar
  </code></pre>
  
  <p>It works if I declare <code>ptr</code> in <code>bar</code> as <code>REAL(KIND=8), DIMENSION(0:10)</code>. But in general I might not know the size of the passed-in array, so is there a way to declare <code>ptr</code> to be a pointer to some array? I am compiling this with <code>gfortran</code></p>