File: common_22.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 (47 lines) | stat: -rw-r--r-- 1,182 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
! Test: Multiple independent COMMON blocks in same program unit (F2018 8.10.3)
! Verifies that different named COMMON blocks have independent storage.
! Modifications to one block should not affect variables in another block.
program common_22
    implicit none
    integer :: a1, a2
    real :: b1, b2
    common/blk1/a1, a2
    common/blk2/b1, b2

    a1 = 10
    a2 = 20
    b1 = 1.5
    b2 = 2.5

    call sub_access_both()
    call sub_verify_independence()
    print *, "PASS: common_22"
end program

subroutine sub_access_both()
    implicit none
    integer :: x1, x2
    real :: y1, y2
    common/blk1/x1, x2
    common/blk2/y1, y2

    ! Verify both blocks accessible
    if (x1 /= 10) error stop "x1 should be 10"
    if (x2 /= 20) error stop "x2 should be 20"
    if (abs(y1 - 1.5) > 0.001) error stop "y1 should be 1.5"
    if (abs(y2 - 2.5) > 0.001) error stop "y2 should be 2.5"

    ! Modify both blocks
    x1 = 100
    y1 = 10.5
end subroutine

subroutine sub_verify_independence()
    implicit none
    ! Access only blk1 - should not affect blk2
    integer :: p, q
    common/blk1/p, q

    if (p /= 100) error stop "p should be 100"
    p = 999
end subroutine