012. Fortran has allocation-on-assignment#
topic: Allocation
Fortran has allocation on assignment,
but you cannot use the allocate
statement for an array that is already allocated.
integer, allocatable :: v(:)
v = [4, 9]
deallocate(v) ! necessary for line below to work
allocate(v, source=[4, 9]) ! same result as above
end
Fortran has allocation on assignment, but you cannot use the ALLOCATE statement for an array that is allocated
— FortranTip (@fortrantip) December 18, 2021
integer, allocatable :: v(:)
v = [4,9]
deallocate(v) ! necessary for line below to work
allocate (v,source=[4,9]) ! same as above
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
with no flags