以下FORTRAN 77代码有什么问题? [英] Whats wrong with the following FORTRAN 77 code?
问题描述
我是FORTRAN 77的新手,我不明白为什么第一个代码显示错误,而第二个代码编译时我希望他们也这样做。
第一个代码(它不会编译并在z中引用一个意外的数据声明语句):
程序FOO
整数x,y
x = 1
y = 2
整数z
z = 3
end
这个代码在功能上与第一个代码类似无错地编译
程序FOO
整数x,y,z
x = 1
y = 2
z = 3
end
我也尝试在第一个代码中禁用隐式变量声明,但没有任何效果。
Fortran是其中一种古怪的定义顶部的所有语言。换句话说,这样可以:
program FOO
整数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.
Fortran is one of those quaint "define everything at the top" languages. In other words, this would be fine:
program FOO
integer x, y
integer z
x = 1
y = 2
z = 3
end
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:
Such non-executable statements must be placed at the beginning of a program, before the first executable statement.
这篇关于以下FORTRAN 77代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!