forked from scivision/fortran2018-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.f90
37 lines (28 loc) · 854 Bytes
/
block.f90
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
program demo_block
!! Shows Fortran 2008 block namespace
!! At BLOCK exit, local allocatables are deallocated, but outer scope allocatable are NOT deallocated
!!
!! program output:
!! ./block
!! block scope j= 42
!! block scope size(B)= 4
!! outer scope i= 10
!! A allocated T size(a) 4
implicit none (type, external)
integer :: i, j
real, allocatable :: A(:)
i = 10
j = 42
flowers: block
integer :: i
real, allocatable :: B(:)
i = 3
print *, 'block scope j=',j !< 42
i = i + 1
allocate(A(i), B(i))
print *, 'block scope size(B)=',size(B) !< 4, deallocates on block exit (not visible in outer scope)
end block flowers
!> next line prints 10, as the outer scope `i` was not in scope of the block
print *, 'outer scope i=',i
print *, 'A allocated',allocated(A),'size(a)',size(A)
end program