问题描述
在Fortran中stop
和exit
有什么区别?
What is the difference between stop
and exit
in Fortran?
两个都可以通过一些错误信息立即终止程序.
Both can terminate the program immediately with some error information.
推荐答案
exit
是一条语句,该语句终止循环或完成其他构造的执行.但是,问题显然是与许多与stop
语句密切相关的编译器提供的作为函数或子例程的非标准扩展有关的.
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.
例如, gfortran提供这样的东西.
由于exit
的这种用法是非标准的,因此您应参考特定实现的文档以了解其采用的形式以及其产生的影响.
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.
另一方面,stop
语句是标准的Fortran语句.该语句启动Fortran程序执行的 normal 终止(并且可以与error stop
语句启动 error 终止的比较).
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).
除了知道终止(通常)执行程序遵循stop
语句并且有停止代码外,实际发生的方式还是对实现开放.关于发生的事情,有一些建议(但仅是建议).例如,在Fortran 2008中,建议
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.
在实践中,exit
通常类似于该名称的C库函数,其作用类似于stop
,没有停止代码(但仍将给定的状态传递回OS).
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).
总而言之,Fortran没有描述stop
和exit
之间的区别. exit
(用于终止)的使用是不可移植的,甚至stop
的效果也未完全定义.
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.
这篇关于"stop"和"stop"之间有什么区别?和“退出";在Fortran中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!