fortran function的result

这个就是用来给返回值换一个名字。
比如:

FUNCTION GetSomeData( someinput ) RESULT( ans )
  ans = f( someinput )
  end function GetSomeData

如果你不写 result(ans)的话,你必须写成

GetSomeData = f( someinput )

这样看起来不好看。实际上,最重要的应用,在于递归调用函数时,给出最终递归结果。

参考帮助文档:
RESULT
Keyword: Specifies a name for a function result.
Normally, a function result is returned in the function’s name, and all
references to the function name are references to the function result.
However, if you use the RESULT keyword in a FUNCTION statement,
you can specify a local variable name for the function result. In this case, all
references to the function name are recursive calls, and the function name must
not appear in specification statements.
The RESULT name must be different from the name of the function.
Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: FUNCTION, ENTRY, RECURSIVE, Program Units and Procedures
Examples
The following shows an example of a recursive function specifying a
RESULT variable:

RECURSIVE FUNCTION FACTORIAL(P) RESULT(L)
    INTEGER, INTENT(IN) :: P
    INTEGER L
    IF (P == 1) THEN
      L = 1
    ELSE
      L = P * FACTORIAL(P - 1)
    END IF
  END FUNCTION

The following shows another example:

 recursive function FindSame(Aindex,Last,Used) &           !Recursive(递归的)
 &  result(FindSameResult)
  type(card) Last
  integer Aindex, i
  logical matched, used(5)
  if( Aindex > 5 ) then
    FindSameResult = .true.
    return
  endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值