Default Status of “Unknown” in Open

断了今生、忘了曾经 提交于 2019-12-10 20:04:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!