This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fwd: variable-length arguments in an external function


Hi all,

I'm new to fortran and I'm having trouble understanding the behaviour
of the following program. It seems that passing an array to an
external function results in odd behaviour.
I would expect the code attached below to return 2.0 and 2.0, instead
of 0.0 and 2.0.

Could anyone point me to the cause and a possible solution of this? Is
it related to the implementation or have I done something illegal in
fortran (in which case I wonder why the gfortran did not warn me)

Best,
Daan van Vugt




module test
contains
  subroutine test_external(f, extra_args)
    implicit none
    real(kind=8), external :: f
    real(kind=8), intent(in), dimension(:) :: extra_args

    write(*,*) f(extra_args)
  end subroutine test_external

  real(kind=8) function f(args)
    implicit none
    real(kind=8), intent(in), dimension(:) :: args
    f = sum(args)
  end function f
end module test

program external_test
  use test
  implicit none
  call test_external(f, (/1.0,1.0/))
  write(*,*) f((/1.0,1.0/))
end


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]