183. If unsure, test whether a variable is ALLOCATED before using DEALLOCATE.#

topic: Allocation

Note

This tip is a draft1.

Since (ALLOCATE / DEALLOCATE) is valid only when a variable is (not allocated / allocated), when the allocation status of a variable is unclear from reading the code you can write

if (allocated(x)) deallocate(x) allocate (x(n))



1

From the perspective of FortranTip Browser, “draft” means that it hasn’t been edited for formatting, hasn’t had corresponding Fortran programs added, the text content hasn’t been enhanced, etc. Draft texts are extracted from the corresponding Tweet using the Twitter API.