“停止"和“停止"有什么区别?和“退出";在 Fortran 中? [英] What is the difference between "stop" and "exit" in Fortran?
问题描述
Fortran中stop
和exit
有什么区别?
两者都可以通过一些错误信息立即终止程序.
exit
在 Fortran 中是终止循环或完成其他构造执行的语句.然而,问题显然是关于非标准扩展,无论是作为函数还是子程序,由许多编译器提供,它与 stop
语句密切相关.
例如,gfortran 提供了这样的东西.p>
由于 exit
的这种使用是非标准的,您应该参考特定实现的文档来了解它采用什么形式以及它具有什么效果.
另一方面,stop
语句是标准的 Fortran 语句.此语句启动 Fortran 程序执行的正常终止(并且可以与启动 error 终止的 error stop
语句进行比较.
除了知道程序的终止(通常)执行遵循 stop
语句并且存在停止代码之外,实际发生的方式再次对实现保持开放.对于会发生什么,有一些建议(但这些只是建议).例如,在 Fortran 2008 中建议
- 将停止代码(可能是整数或字符串)打印到错误"单元;
- 如果停止码是整数,则作为进程退出状态;
- 如果没有停止代码(或字符),则返回零作为退出状态.
上述内容相当模糊,因为在许多情况下上述概念并不适用.
通常在实践中,exit
将类似于 C 库的该名称的函数,其效果就像 stop
没有停止代码(但仍然传递给定的状态返回给操作系统).
总之,Fortran 没有描述 stop
和 exit
之间的区别.exit
的使用(用于终止)是不可移植的,甚至 stop
的效果也没有完全定义.
What is the difference between stop
and exit
in Fortran?
Both can terminate the program immediately with some error information.
exit
in Fortran is a statement which terminates loops or completes execution of other constructs. However, the question is clearly about the non-standard extension, as either a function or subroutine, offered by many compilers which is closely related to the stop
statement.
For example, gfortran offers such a thing.
As this use of exit
is non-standard you should refer to a particular implementation's documentation as to what form this takes and what effects it has.
The stop
statement, on the other hand, is a standard Fortran statement. This statement initiates normal termination of execution of a Fortran program (and can be compared with the error stop
statement which initiates error termination).
Other than knowing that terminating (normally) execution of the program follows a stop
statement and that there is a stop code, the actual way that happens are again left open to the implementation. There are some recommendations (but these are only recommendations) as to what happens. For example, in Fortran 2008 it is suggested that
- the stop code (which may be an integer or a string) be printed to an "error" unit;
- if the stop code is an integer it be used as the process exit status;
- if there is no stop code (or it's a character) zero be returned as the exit status.
The above is fairly vague as in many settings the above concepts don't apply.
Typically in practice, exit
will be similar to the C library's function of that name and its effect will be like stop
without a stop code (but still passing the given status back to the OS).
In summary, Fortran doesn't describe a difference between stop
and exit
. Use of exit
(for termination) is non-portable and even the effect of stop
is not entirely defined.
这篇关于“停止"和“停止"有什么区别?和“退出";在 Fortran 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!