Fwd: variable-length arguments in an external function
Daan van Vugt
daanvanvugt@gmail.com
Mon Jun 1 12:33:00 GMT 2015
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
More information about the Fortran
mailing list