Fortran中BLOCK的意义是什么? [英] What is the point of BLOCK in Fortran?
问题描述
我正在查看一些代码,它是这样的:
I am looking at some code and there is this:
BLOCK
...lines of code...
END BLOCK
BLOCK
的目的是什么?我试图用谷歌搜索它,但是我发现的只是关于BLOCK DATA
和COMMON
块的东西.我不确定它们是否相关.
What is the purpose of BLOCK
? I tried to google it, but all I found was something about BLOCK DATA
and COMMON
blocks. I'm not sure whether they are related.
推荐答案
根据Fortran 2008标准:
From the Fortran 2008 standard:
BLOCK构造是一个可执行的构造,其中可能包含声明.
The BLOCK construct is an executable construct that may contain declarations.
它与通用块或块数据程序单元无关.
It is not related to common blocks or to block data program units.
因此,主要用途是此包含声明".
So, the main use is this "containing declarations".
作为范围划分单位,我们有类似的东西
As scoping units we have things like
integer i
block
integer j ! A local integer
integer i ! Another i
save i ! ... which can even be SAVEd
end block
提供声明的位置:
! ... lots of code
block
integer something
read *, something
end block
! ... lots more code
这些作用域块允许自动对象:
integer i
i = 5
block
real x(i)
end block
作为可执行结构,它们还具有有用的流控制:
As executable constructs, they also have useful flow control:
this_block: block
if (something) exit this_block
! ... lots of code
end block
它们还具有最终确定控制权:
They also have finalization control:
type(t) x
block
type(t) y
end block ! y is finalized
end ! x is not finalized
用于x
和y
的可终结类型.
哦,让我们不要忘记如何将人们与隐式键入混淆.
Oh, and let's not forget how you can confuse people with implicit typing.
这篇关于Fortran中BLOCK的意义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!