Silverfrost Forums

Welcome to our forums

Undefined function argument

4 Apr 2022 6:02 #28864

The following program creates an array ia, and then calls function f1, which in turn calls function f2 to assign some values to the array. Function f2 apparently is returning ia as undefined. If you change f2 to a subroutine, the behaviour is as expected.

I am using FTN95 version 8.83. I have not tried this program with other versions.

Module m
   Integer, Dimension(:), Allocatable, Public :: ia
Contains
!
 Subroutine s1 (n)
   Integer, Intent(In) :: n
!
   Allocate (ia(n))
   Return
 End Subroutine s1
!
 Function f1()
   Integer :: f1
   f1 = f2(ia(:))
   print*,'f1:',ia(:)
!
   Return
 End Function f1
!
 Function f2(ia2)
   Integer :: f2
   Integer, Dimension(:), Intent(Out) :: ia2
!
   ia2(:) = 1
   Print*,'f2:',ia2(:)
   f2 = 0
   Return
 End Function f2
End Module m
!
Program p
   Use m
   Integer :: i

   Call s1(5)
   i = f1()
End Program p
4 Apr 2022 7:16 #28865

Simon

At the moment I don't think that this is a regression in FTN95 and it is probably a bug that needs fixing.

The failure relates to passing the array section in the line

   f1 = f2(ia(:))

If you replace this line with

   f1 = f2(ia)

then the program runs correctly.

4 Apr 2022 3:09 #28868

Thanks Paul. I can certainly implement

f1 = f2(ia)

in a few cases. But since it is not always a simple option, I will look into converting f2 to a subroutine, which seems to avoid the problem too.

8 Oct 2022 4:34 #29411

This failure has now been fixed for the next release of FTN95.

Please login to reply.