gpt4 book ai didi

multithreading - Fortran 基本函数与基本子例程

转载 作者:行者123 更新时间:2023-12-04 08:14:58 26 4
gpt4 key购买 nike

Fortan 允许基本子程序具有intent(inout) 和intent(out) 参数,但基本函数只允许intent(in)。

这是为什么?它只是一种风格约定,还是在调用函数和调用子例程方面有一些普遍的不同?

换句话说,

Elemental Integer Function FOO(i)
Integer, intent(in) :: i
...
FOO=something
End Function


Elemental Subroutine FOO(i, v)
Integer, intent(in) :: i
Integer, intent(out) :: v
...
v=something
End Subroutine

——这些 FOO 的实现是否同样有效?

最佳答案

没有至少一个标记为 intent(out) 的参数的基本子例程是没有意义的。或 intent(inout) ,因为您必须以某种方式传递结果。一个函数有它的返回值,一个子程序必须使用它的参数。在 Fortran 2008 AFAIK 中,基本程序不一定是纯的,但很难想象一个有用的基本子程序仅通过其副作用。

关于multithreading - Fortran 基本函数与基本子例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6879261/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com