File: passing_array_02.f90

package info (click to toggle)
lfortran 0.45.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 46,332 kB
  • sloc: cpp: 137,068; f90: 51,260; python: 6,444; ansic: 4,277; yacc: 2,285; fortran: 806; sh: 524; makefile: 30; javascript: 15
file content (61 lines) | stat: -rw-r--r-- 1,683 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
MODULE passing_array_02_mod
    implicit none

    INTERFACE test_01_interface
       MODULE PROCEDURE test_01
    END INTERFACE test_01_interface

    INTERFACE test_02_interface
       MODULE PROCEDURE test_02
    END INTERFACE test_02_interface

    CONTAINS
 
    FUNCTION test_01 (len,value) result(res)
        implicit none
        INTEGER, intent(in) :: len 
        ! Passed integer `len` is set to 10, which should result to an error (12/30)
        ! but as len isn't known at compile time, it just accepts it.
        INTEGER, DIMENSION(3,len),intent(in) :: value 
        INTEGER :: res
        res = size(value)
    END FUNCTION test_01

    FUNCTION test_02 (value) result(res)
        implicit none
        ! Passed array has dimension = 12 while the array in this function has dimension = 3
        ! Slicing is premesible (3 <= 12), so accept it.  
        INTEGER, DIMENSION(3,1),intent(in) :: value 
        INTEGER :: res
        res = size(value)
    END FUNCTION test_02

    subroutine test_entry
        integer:: len
        INTEGER, DIMENSION(6,2) :: arr
        INTEGER :: ret
        len = 10
        ret =  test_01_interface (len,arr)
        print * , ret
        if (ret /= 30) error stop
  
        ret =  test_01 (len,arr)
        print * , ret
        if (ret /= 30) error stop
  
        ret =  test_02_interface (arr)
        print * , ret
        if (ret /= 3) error stop
  
        ret =  test_02 (arr)
        print * , ret
        if (ret /= 3) error stop

    end subroutine test_entry
 
END MODULE passing_array_02_mod
program passing_array_02
    use passing_array_02_mod
    implicit none
    call test_entry
end program passing_array_02