Fortran 返回语句 [英] Fortran return statement

查看:29
本文介绍了Fortran 返回语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 gfortran 下编译一些在 g77 下编译良好的代码.问题似乎来自一个return语句:

I'm trying to get some code compiled under gfortran that compiles fine under g77. The problem seems to be from a return statement:

ffuncs.f:934.13:

ffuncs.f:934.13:

  RETURN E
         1

错误:(1) 处的备用 RETURN 语句需要 SCALAR-INTEGER 返回说明符

Error: Alternate RETURN statement at (1) requires a SCALAR-INTEGER return specifier

在代码中,任何 E 都被指定为实数*8:

In the code anything E was specified as real*8:

隐式实数*8 ( A - H , O -Z )

IMPLICIT REAL*8 ( A - H , O -Z )

然而,E 从来没有被赋予一个值或任何东西,事实上你在 return 语句之前永远不会看到它.我对fortran几乎一无所知.fortran中带参数的return语句是什么意思?

However, E was never given a value or anything in fact you never see it until the return statement. I know almost nothing about fortran. What is the meaning of a return statement with an argument in fortran?

谢谢.

推荐答案

在 FORTRAN 中(一直到 Fortran 77,我很熟悉),RETURN n 不用于返回函数价值;相反,它执行的操作类似于在其他语言中将由异常处理:退出到正常位置以外的代码位置.

In FORTRAN (up to Fortran 77, which I'm very familiar with), RETURN n is not used to return a function value; instead, it does something like what in other languages would be handled by an exception: An exit to a code location other than the normal one.

你通常会用标签作为参数调用这样的 SUBROUTINEFUNCTION,例如

You'd normally call such a SUBROUTINE or FUNCTION with labels as arguments, e.g.

  CALL MYSUB(A, B, C, *998, *999)
...
998 STOP 'Error 1'
998 STOP 'Error 2'

如果 MYSUB 出现问题,那么您执行 RETURN 1RETURN 2 (而不是正常的 RETURN),您将直接跳到标签 998 或999 在调用例程中.

and if things go wrong in MYSUB then you do RETURN 1 or RETURN 2 (rather than the normal RETURN) and you'd be hopping straight to label 998 or 999 in the calling routine.

这就是为什么通常您希望在该 RETURN 上使用一个整数 - 它不是一个值,而是您想要退出的错误的索引.

That's why normally you want an integer on that RETURN - it's not a value but an index to which error exit you want to take.

RETURN E 对我来说听起来不对.除非有我不知道的语法,否则以前的编译器应该将其标记为错误.

RETURN E sounds wrong to me. Unless there's a syntax I'm unaware of, the previous compiler should have flagged that as an error.

这篇关于Fortran 返回语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆