File: associate_24.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 (32 lines) | stat: -rw-r--r-- 806 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
program mre
    implicit none

    type :: line_token
        integer :: first, second
    end type

    type(line_token), allocatable :: token(:)
    integer :: shift(4)

    allocate(token(4))
    token%first = [1, 2, 3, 4]

    associate(first => token%first)
        shift = first - 1
        first = first + 1
    end associate

    ! Check that shift = first - 1 worked (original values were 1,2,3,4)
    if (shift(1) /= 0) error stop
    if (shift(2) /= 1) error stop
    if (shift(3) /= 2) error stop
    if (shift(4) /= 3) error stop

    ! Check that first = first + 1 modified the original array
    if (token(1)%first /= 2) error stop
    if (token(2)%first /= 3) error stop
    if (token(3)%first /= 4) error stop
    if (token(4)%first /= 5) error stop

    print *, "PASSED"
end program mre