This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Fwd: variable-length arguments in an external function
- From: Daan van Vugt <daanvanvugt at gmail dot com>
- To: fortran at gcc dot gnu dot org
- Date: Mon, 1 Jun 2015 14:33:32 +0200
- Subject: Fwd: variable-length arguments in an external function
- Authentication-results: sourceware.org; auth=none
- References: <CAAyVbOAr2a9NnReEvPuKE3FTkxKZs0YrWUZVU=XomNRVb3xLBA at mail dot gmail dot com>
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