-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathassociate_alloc.f90
More file actions
27 lines (27 loc) · 874 Bytes
/
associate_alloc.f90
File metadata and controls
27 lines (27 loc) · 874 Bytes
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
program associate_alloc
implicit none
integer, allocatable :: v(:)
v = [3,4] ! must allocate v before associating c to it
associate (c => v) ; call disp("1",v,c)
c = c*10 ; call disp("2",v,c)
! line below is invalid -- v should not be reallocated while
! c is still ASSOCIATEd to it
v = [2] ; call disp("3",v,c)
end associate
contains
subroutine disp(label,v,c)
character (len=*), intent(in) :: label
integer, intent(in) :: v(:),c(:)
write (*,"(a,' v = ',*(1x,i0))",advance="no") label,v
write (*,"(3x,'c = ',*(1x,i0))") c
end subroutine disp
end program associate_alloc
! gfortran output:
! 1 v = 3 4 c = 3 4
! 2 v = 30 40 c = 30 40
! 3 v = 2 c = 2 40
! Intel Fortran output:
! 1 v = 3 4 c = 3 4
! 2 v = 30 40 c = 30 40
! 3 v = 2 c = 30 40
! the output differs for the last line, which is invalid