Silverfrost Forums

Welcome to our forums

Pure function - dummy argument intent(out)

24 Feb 2025 12:47 #31942

The following program compiles and runs with FTN95.

However, since the function F1 is PURE its dummy arguments can only have INTENT(in).

Both iFort and gFortran complain about this code but not FTN95.

I discovered this one PURELY by accident!

module test
implicit none
contains
  
  pure function f1(a, rc) result( y )
  real, intent(in) :: a
  integer, intent(out) :: rc
  real :: y
    if (a .lt. 0.0) then
      y = 0.0
      rc = 0
    else   
      y = sqrt(a)
      rc = 1
    end if
  end function f1
  
end module test

program p
use test
implicit none
real a, b
integer rc
 a = -2.0
 b = f1(a, rc)
 print*, a, b, rc
 a = 2.0
 b = f1(a, rc)
 print*, a, b, rc
end program p
  
25 Feb 2025 10:37 #31943

Ken

Thank you for the valued feedback. This has now been fixed for the next release of FTN95.

Please login to reply.