问题
I often see people using the OPEN
statement without explicitly specifying a STATUS
. In the Fortran 90 and 2008 standards, this is said regarding STATUS
:
If UNKNOWN is specified, the status is processor dependent. If this specifier is omitted, the default value is UNKNOWN.
I interpret this to mean, if STATUS
is omitted, anything can happen, depending what machine you're using.
Yet, from doing some tests, it seems the default behavior (when STATUS
is omitted), is REPLACE
. But I cannot find this behavior documented in the gfortran compiler manual (from https://gcc.gnu.org/onlinedocs/).
Question: Is this REPLACE
indeed the default behavior in popular compilers like gfortran and ifort? If so, is this actually documented (but I just happened to not find it)?
回答1:
In common compilers the UNKNOWN
behaves quite similarly in all of them. But it definitely is not equivalent to REPLACE
! That choice would overwrite your data you want to read!
The IBM XL Fortran manual specifies this:
UNKNOWN, to connect an existing file, or to create and connect a new file. If the file exists, it is connected as OLD. If the file does not exist, it is connected as NEW.
回答2:
UNKNOWN means create the file if not yet existing, then open it.
来源:https://stackoverflow.com/questions/27340943/default-status-of-unknown-in-open