019. associate
creates an alias for expressions or variables#
topic: Associate
integer, allocatable :: u(:)
u = [4,9]
associate (v => u)
v = v - 2
print *, v ! 2 7
print *, u ! 2 7
associate (w => [4, 9])
print *, w
! The following is illegal since `w` is set to a constant expression;
! it will raise a compilation error:
! w = w - 2
! Need one for each of the `associate`s above
end associate
end associate
end
2 7
2 7
4 9
Associate creates an alias for expressions or variables.
— FortranTip (@fortrantip) December 19, 2021
integer, allocatable :: u(:)
u = [4,9]
associate (v => u)
v = v - 2
print*,v ! 2 7
print*,u ! 2 7
associate (w => [4,9])
print*,w
w = w - 2 ! illegal since w set to a constant expression
end associate
end associate
end
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags