Fortran函数和返回值

编程入门 行业动态 更新时间:2024-10-13 12:17:39
本文介绍了Fortran函数和返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在Fortran中编写一个将输入和输出都作为参数的函数?例如:

How can I write a function in Fortran which takes both input and output as arguments? For example:

fun(integer input,integer output)

我想要使用输出值。我试过类似的东西,但输出变量不包含该值。

I want to make use of the output value. I have tried something like this but the output variable is not holding the value.

具体而言,我从Fortran中调用一个C函数,它将输入和输出作为参数。我能够成功传递输入值,但输出变量没有获取值。

Specifically, I am calling a C function from Fortran which takes input and output as parameters. I am able to pass input values successfully, but the output variable is not acquiring a value.

推荐答案

像我这样的Fortran程序员打电话给SUBROUTINE(是的,我们也在Fortran城里喊我们的关键字)。一个函数是一个像这样的返回值的东西:

Your fun() is what Fortran programmers, such as me, call a SUBROUTINE (yes, we shout our keywords in Fortran-town too). A FUNCTION is a value-returning thing like this:

sin_of_x = sin(x)

因此,您的第一个决定是您的Fortran代码采用哪种方法。你可能想要使用SUBROUTINE。然后理清你的论点的意图。

So your first decision is which approach your Fortran code will take. You probably want to use SUBROUTINE. Then sort out the INTENT of your arguments.

更多推荐

Fortran函数和返回值

本文发布于:2023-11-26 02:29:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632291.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   返回值   Fortran

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!