title: Segmentation fault, when passing functions with array arguments to subroutine in Fortran
body: <p>I am working on a project (which is due tomorrow :/) and encountered a problem when I tried to use a simplex algorithm on a function I wrote myself. It didn't work, and after now 5 hours of searching and experimenting, I found out the following:</p>
  
  <p>When I pass a function to a subroutine, this function can't have any array arguments. Is this true? Because in the code that I am supposed to use it evidently SHOULD work.</p>
  
  <p>I am using the ifort compiler. See below for a minimum example, which I basicaly took from <a href="http://malayamaarutham.blogspot.de/2006/02/passing-function-names-as-arguments-in.html" rel="nofollow">http://malayamaarutham.blogspot.de/2006/02/passing-function-names-as-arguments-in.html</a></p>
  
  <pre><code>  ! Author : Kamaraju S Kusumanchi
    ! Email  : kamaraju@gmail.com
    ! Last edited : Sun Feb  5 2006
    !
    ! Sample program demonstrating the use of external attribute.        This program
    ! shows how to pass function names as arguments in Fortran 90       programs.
    !
    ! Compilation and execution steps
    ! $gfortran passing_functions.f90 -o passing_functions
    ! $./passing_functions
    !  beta =    5.500000
    !  beta =    1.500000
    !
    ! I would appreciate any comments, feedback, criticism,       mistakes, errors etc.,
    !   (however minor they are)
    !
    module dummy
      implicit none
    contains
    !------------------------------------------------------------------------------
    function func1(a)
      implicit none
      real :: a
      real :: func1
  
      func1 = a+5
    end function func1
    !------------------------------------------------------------------------------
    function func2(b)
      implicit none
      real :: b(:)
      real :: func2
  
      func2 = b(1)
    end function func2
    !------------------------------------------------------------------------------
    function func3(dyn_func, c)
      implicit none
      real :: c
      real, external :: dyn_func
      real :: func3
  
      func3 = dyn_func(c)
    end function func3
    !------------------------------------------------------------------------------
    function func4(dyn_func, c)
      implicit none
      real :: c(*)
      real, external :: dyn_func
      real :: func4
  
      func4 = dyn_func(c)
    end function func4
    end module dummy
    !------------------------------------------------------------------------------
  
    program passing_functions
      use dummy
      implicit none
  
      real :: alpha=0.5, beta
      real :: gamma(2) = (/10,20/)
  
      beta = func3(func1, alpha)
      write(*,*) 'beta = ', beta
      beta = func4(func2, gamma)
      write(*,*) 'beta = ', beta
    end program passing_functions
  </code></pre>
  
  <p>This is the output:</p>
  
  <pre><code>zeus$ passing.out
   beta =    5.500000    
  forrtl: severe (174): SIGSEGV, segmentation fault occurred
  Image              PC                Routine            Line        Source             
  passing.out        0000000000402D44  Unknown               Unknown  Unknown
  passing.out        0000000000402C7C  Unknown               Unknown  Unknown
  libc.so.6          00002AFF7915D23D  Unknown               Unknown  Unknown
  passing.out        0000000000402B79  Unknown               Unknown  Unknown
  zeus$ 
  </code></pre>