What is the point of BLOCK in Fortran?

  • A+

I am looking at some code and there is this:

BLOCK  ...lines of code...  END BLOCK 

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.


From the Fortran 2008 standard:

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 

which affords locality of declarations:

! ... lots of code block   integer something   read *, something end block ! ... lots more code 

These scoping blocks allow automatic objects:

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 

for x and y of finalizable type.

Oh, and let's not forget how you can confuse people with implicit typing.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: