| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-fcheck=recursion" } |
| 3 |
! |
| 4 |
! PR fortran/39577 |
| 5 |
! |
| 6 |
! Recursive but valid program |
| 7 |
! Contributed by Dominique Dhumieres |
| 8 |
! |
| 9 |
recursive function fac(i) result (res) |
| 10 |
integer :: i, j, k, res |
| 11 |
k = 1 |
| 12 |
goto 100 |
| 13 |
entry bifac(i,j) result (res) |
| 14 |
k = j |
| 15 |
100 continue |
| 16 |
if (i < k) then |
| 17 |
res = 1 |
| 18 |
else |
| 19 |
res = i * bifac(i-k,k) |
| 20 |
end if |
| 21 |
end function |
| 22 |
|
| 23 |
program test |
| 24 |
interface |
| 25 |
recursive function fac(n) result (res) |
| 26 |
integer :: res |
| 27 |
integer :: n |
| 28 |
end function fac |
| 29 |
recursive function bifac(m,n) result (res) |
| 30 |
integer :: m, n, res |
| 31 |
end function bifac |
| 32 |
end interface |
| 33 |
|
| 34 |
print *, fac(5) |
| 35 |
print *, bifac(5,2) |
| 36 |
print*, fac(6) |
| 37 |
print *, bifac(6,2) |
| 38 |
print*, fac(0) |
| 39 |
print *, bifac(1,2) |
| 40 |
end program test |