File: kwargs_01.f90

package info (click to toggle)
lfortran 0.60.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,416 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 38; javascript: 15
file content (60 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (2)
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
program kwargs_01
! Test keyword arguments
implicit none

integer :: i

i = f(1, 2, 3, 4)
if (i /= 1234) error stop
call s(1, 2, 3, 4, i)
if (i /= 1234) error stop

i = f(1, 2, 3, d=4)
if (i /= 1234) error stop
call s(1, 2, 3, d=4, f=i)
if (i /= 1234) error stop

i = f(1, 2, c=3, d=4)
if (i /= 1234) error stop
call s(1, 2, c=3, d=4, f=i)
if (i /= 1234) error stop

i = f(1, 2, d=3, c=4)
if (i /= 1243) error stop
call s(1, 2, d=3, c=4, f=i)
if (i /= 1243) error stop

i = f(1, b=2, c=3, d=4)
if (i /= 1234) error stop
call s(1, b=2, c=3, d=4, f=i)
if (i /= 1234) error stop

i = f(1, c=2, d=3, b=4)
if (i /= 1423) error stop
call s(1, c=2, d=3, b=4, f=i)
if (i /= 1423) error stop

i = f(a=1, b=2, c=3, d=4)
if (i /= 1234) error stop
call s(a=1, b=2, c=3, d=4, f=i)
if (i /= 1234) error stop

i = f(d=1, c=2, a=3, b=4)
if (i /= 3421) error stop
call s(d=1, c=2, a=3, b=4, f=i)
if (i /= 3421) error stop

contains

    integer function f(a, b, c, d)
    integer, intent(in) :: a, b, c, d
    f = a*1000 + b*100 + c*10 + d
    end function

    subroutine s(a, b, c, d, f)
    integer, intent(in) :: a, b, c, d
    integer, intent(out) :: f
    f = a*1000 + b*100 + c*10 + d
    end subroutine

end program