File: implicit_interface_23.f90

package info (click to toggle)
lfortran 0.60.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,412 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 37; javascript: 15
file content (40 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
! Test implicit interface procedure dummy with mixed call patterns
! When a procedure dummy f is:
!   1. Passed as argument to another subroutine
!   2. Called with both variable args f(x) and expression args f(x+1)
! All calls should use consistent by-reference calling convention
program implicit_interface_23
    implicit none
    double precision :: x, result
    x = 2.0d0
    call compute(square, x, result)
    ! Expected: square(2) + square(3) = 4 + 9 = 13
    if (abs(result - 13.0d0) > 1.0d-10) error stop
    print *, "PASS"
contains
    double precision function square(y)
        double precision, intent(in) :: y
        square = y * y
    end function
end program

subroutine compute(f, x, result)
    implicit none
    double precision, intent(in) :: x
    double precision, intent(out) :: result
    double precision :: f, tmp
    external :: f
    ! Pass f to another subroutine first (creates implicit interface)
    tmp = x
    call use_func(f, tmp)
    ! Then call f with both variable and expression arguments
    result = f(x) + f(x + 1.0d0)
end subroutine

subroutine use_func(g, z)
    implicit none
    double precision, intent(inout) :: z
    double precision :: g
    external :: g
    z = g(z)
end subroutine