webpage icon indicating copy to clipboard operation
webpage copied to clipboard

Mention allocation-on-assignment in allocatable array section

Open Beliavsky opened this issue 1 year ago • 0 comments

The information at https://fortran-lang.org/en/learn/best_practices/allocatable_arrays/ is correct, but in the snippet

An already allocated array cannot be allocated again without prior deallocation. Similarly, deallocation can only be invoked for allocated arrays. To reallocate an array use

if (allocated(lam)) deallocate(lam)
allocate(lam(10))

I think allocation-on-assignment should be mentioned, since that will often make code simpler. I may submit a PR.

Beliavsky avatar Nov 21 '24 17:11 Beliavsky