[J3] Finalization Question
Vipul Parekh
parekhvs at gmail.com
Fri May 27 12:50:50 UTC 2022
On Fri, May 27, 2022 at 12:53 AM Malcolm Cohen via J3 <
j3 at mailman.j3-fortran.org> wrote:
> ..
> A specification function is what you are looking for here. However, such a
> function must be pure, and so the final subroutine must be pure, and
> therefore cannot set a global variable or print a message, so it can be
> hard to tell whether it ran. If your compiler supports memory allocation
> tracing, you can use pointer components to observe that yes, the final
> subroutine does get executed (unless the compiler has a bug!). Or if the
> compiler does not support memory allocation tracing, you could allocate a
> 500MB array component in the function (and deallocate it in the finaliser!)
> and run it a million times to check that you don't run out of virtual
> memory (or you are on a 500TB machine).
>
Starting Fortran 2018, one can employ the ERROR STOP statement as a way to
determine whether the final procedure was invoked.
The example I showed in my previous note in this thread indeed makes use of
this facility.
Vipul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20220527/e9ad89b1/attachment.htm>
More information about the J3
mailing list