Aleksandar Donev wrote:
> Hi,
>
> I am playing with some signal handling in my Fortran codes (via C
> Interoperability). I am wondering what the guarantees on the STOP
> statement are in terms of orderly termination: In particular, closing
> files and cleaning up (non-pointer allocated) memory (and running
> FINALizers in F2003)? Are there any requirements. I don't think one can
> do better than STOP often unless one develops a rather sophisticated
> manual system for propagating signals (exceptions) across procedure
> calls, which I am not yet ready to do...
>
> Thanks,
> Aleksandar
>
The paragraph just before 2.4 in the DIS says
"Normal termination of execution of the program occurs if a
STOP statement or end-program-stmt is executed. Normal
termination of execution of a program also may occur during
execution of a procedure defined by a companion processor (C
International Standard 5.1.2.2.3 and 7.20.4.3). If normal
termination of execution occurs within a Fortran program
unit and the program incorporates procedures defined by a
companion processor, the process of execution termination
shall include the effect of executing the C exit() function
(C International Standard 7.20.4.3)."
So, I'd say that executing a STOP does whatever an
end program statement does.
Note that in
"4.5.5.3 Entities that are not finalized
If program execution is terminated, either by an error (e.g.
an allocation failure) or by execution of a STOP or END
PROGRAM statement, entities existing immediately prior to
termination are not finalized."
So, it looks like things are not finalized.
The last paragraph of section 8 says
".... If any exception (14) is signaling, the processor
shall issue a warning indicating which exceptions are
signaling; this warning shall be on the unit identified by
the named constant ERROR_UNIT from the ISO_FORTRAN_ENV
intrinsic module (13.8.2.2)."
But, apparently, this isn't required for ending with an end.
And just before note 9.22 it says
"At normal termination of execution of a program for reasons
other than an error condition, all units that are connected
are closed. Each unit is closed with status KEEP unless the
file status prior to termination of execution was SCRATCH,
in which case the unit is closed with status DELETE."
So, files are cleaned up.
Looks to me like everything you want happens, except for
finalizing, and you get the bonus of exception reporting.
Dick Hendrickson
|