以下 FORTRAN 77 代码有什么问题?
我是一个 FORTRAN 77 新手,我不明白为什么第一个代码显示错误,而第二个代码在我期望它们做同样的事情时编译。
第一个代码(不会编译并给出错误,引用 z 处的意外数据声明语句):
program FOO
integer x, y
x = 1
y = 2
integer z
z = 3
end
此代码在功能上看起来与第一个代码 100% 相似,编译时没有错误
program FOO
integer x, y, z
x = 1
y = 2
z = 3
end
我还尝试在第一个代码中禁用隐式变量声明没有影响。
I am a total FORTRAN 77 newbie, and I don't understand why the first code shows an error while the second one compiles when I expect them to do the same.
First code (which doesn't compile and gives a error citing an unexpected data declaration statement at z):
program FOO
integer x, y
x = 1
y = 2
integer z
z = 3
end
This code which looks 100% similar in functionality to the first one compiles without errors
program FOO
integer x, y, z
x = 1
y = 2
z = 3
end
I also tried disabling implicit variable declarations in the first code with no effects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Fortran 是一种奇特的“在顶层定义一切”语言。换句话说,这很好:
因为所有类型规范都位于任何可执行代码之前。如果您要定义一个变量,您应该首先定义它。请参阅此处例如:
Fortran is one of those quaint "define everything at the top" languages. In other words, this would be fine:
since all type specifications are before any executable code. If you're going to define a variable, you should define it first. See here for example:
我不知道真正的解决方案,但也许
fortran77
不支持变量之间的任何代码。例如;
有效但
不起作用。因为在两个整数定义之间(
integer x, y
和integer z
),存在变量赋值。I don't know real solution but maybe
fortran77
doesn't support any code between variables.for example;
works but
doesn't work. Because between two integer definening (
integer x, y
andinteger z
), there are variables assigning.@paxdiablo:你想得对!
和错误消息:
“...意外的数据声明语句在...”
所有 DELCARATION 必须在第一个 STATMENT 出现之前进行。 fortran77 真的很“旧”,我不确定 F95 中是否会改变这一点
@paxdiablo: you think right!
and the errormessage:
"... unexpected data declaration statement at ..."
all DELCARATION must be made BEFORE the first STATEMENT occurs. fortran77 is really "old", I´m not shure if this is changed in F95
供您参考:禁用隐式变量声明只会消除 Fortan 假设变量类型的能力。
隐式变量声明做出以下假设: 任何以(大写或小写)开头的变量:I、J、K、L、M 或 N 均为 INTEGER。任何以任何其他字母(大写或小写)开头的变量都是 REAL。这仅适用于没有显式类型声明的变量。
您可以编写:
ijk 和 ifjkask 将为 INTEGER 值。
For your information: Disabling implicit variable declarations simply removes Fortan's ability to make assumptions about what type your variables are.
Implicit variable declaration makes the following assumptions: Any variable beginning with (capital or lowercase): I, J, K, L, M, or N is to be INTEGER. Any variable beginning with any other letter (capital or lowercase) is to be REAL. This applies only to variables which do not have an explicit type declaration.
You could write:
and ijk and ifjkask would be INTEGER values.