fortran - Fortran中BLOCK的意义是什么?

标签 fortran

我正在看一些代码,这是:

BLOCK

...lines of code...

END BLOCK
BLOCK的作用是什么?我试图用Google搜索它,但发现的只是关于BLOCK DATACOMMON块的信息。我不确定它们是否相关。

最佳答案

根据Fortran 2008标准:

The BLOCK construct is an executable construct that may contain declarations.



它与通用块或块数据程序单元无关。

因此,主要用途是此“包含声明”。

作为作用域单位,我们有类似
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

这些作用域块允许automatic objects:
integer i
i = 5
block
  real x(i)
end block

作为可执行结构,它们还具有有用的flow control:
this_block: block
  if (something) exit this_block
  ! ... lots of code
end block

他们还具有最终控制权:
type(t) x
block
  type(t) y
end block ! y is finalized
end  ! x is not finalized

用于终结类型的xy

哦,别忘了如何将人们与隐式输入混淆。

关于fortran - Fortran中BLOCK的意义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51475773/

相关文章:

ubuntu - gfortran 编译目标文件错误 crt1.o : In function `_start' :

pointers - Fortran 中重载箭头运算符 (=>)

compiler-errors - 错误无法分配给常量

fortran - 在Fortran中,在扩展定义时,如何将公共(public)过程设置为私有(private)?

arrays - 错误 : The part-name to the right of a part-ref with nonzero rank has the ALLOCATABLE attribute

c - 通过C函数定义的Fortran派生类型构造函数(二)

c++ - 编译混合的 GNU Fortran/C++ MPI 共享库

memory-management - forrtl : severe (179): Cannot allocate array - overflow on array size calculation

在 Fortran 中调用 C 函数,其中参数是指针

fortran - 如何在循环中单行打印?