Kenneth_Smith
Joined: 18 May 2012 Posts: 799 Location: Hamilton, Lanarkshire, Scotland.
|
Posted: Mon Feb 24, 2025 1:47 am Post subject: Pure function - dummy argument intent(out) |
|
|
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!
Code: | 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
|
|
|