FORTRAN 中函数的基本结构是什么?
这是我最近想知道的事情,主要是出于好奇。 我想学习一些旧的编码风格,FORTRAN 似乎是一个很好的起点。
我想我应该通过提供一个好的起点来帮助你们。
那么这个 C 程序如何用 FORTRAN 编写呢?
int foo ( int x , int y )
{
int tempX = x ;
x += y / 2 ;
y -= tempX * 3 ; // tempX holds x's original value.
return x * y ;
}
我知道整个函数可以是一行:
return ( x + ( y / 2 ) ) * ( y - ( x * 3 ) ) ;
但我问这个问题的目的是看看这四个语句如何在 FORTRAN 中单独编写,而不一定组合成单个语句。
This is something that's I've wanted to know recently, mostly out of curiousity. I'm in the mood to learn some old coding styles, and FORTRAN seems like a good place to start.
I guess I should help you guys out by providing a good starting point.
So how would this C procedure be written in FORTRAN?
int foo ( int x , int y )
{
int tempX = x ;
x += y / 2 ;
y -= tempX * 3 ; // tempX holds x's original value.
return x * y ;
}
I know the entire function could be a single line:
return ( x + ( y / 2 ) ) * ( y - ( x * 3 ) ) ;
But the point of me asking this question is to see how those four statements would be written individually in FORTRAN, not neccessarily combined into a single statement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不要责怪我 - 你说的是旧编码风格:
当我写这篇文章时,我不寒而栗,但
J
位于末尾,以提供与原始函数相同的效果(即按值传递,因此x
和y
在调用例程中没有改变)请,请,请永远不要编写这样的新代码,除非是开玩笑。
Don't blame me - you said old coding styles:
I shudder as I write this, but
I
andJ
at the end to give the same effect as the original function (i.e. pass-by-value, sox
andy
were unchanged in the calling routine)Please, please, please never write new code like this unless as a joke.
您的函数在 Fortran 中可能如下所示
您应该能够开始使用有关 Fortran 的任何教程。 像这样的事情可能会有所帮助 http://www.cs .mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html
干杯
Your function might look like this in Fortran
You should be able to get started with any tutorial on Fortran. Some thing like this might help http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html
cheers
请参阅函数和子例程:
然后:
See Functions and Subroutines:
then later:
你从哪里学习 FORTRAN? 只需看看wikibook!
从这个例子中,我想说:
Where do you learn FORTRAN from? Just take a look at the wikibooks!
Derived from the example, I'd say:
与上面类似,但用一个主程序来说明它是如何调用的。
注意,这是Fortran 77,是我23年前学的。
Similar to above, but with a main program to illustrate how it would be called.
Note that this is Fortran 77, which is what I learned 23 years ago.
应用整数规则 IJKLMN 的真正旧风格
True old style in applying the rule IJKLMN for integer