Question about the use of common blocks

I see now, thanks for the explanation. Indeed, to do it reliably for modules, you would need help from the compiler.

What I would like is to be able to debug as if Fortran was Python, so you could interactively set or read variables (in modules too), etc. This might only work in Debug mode, as there might be some performance overhead.

Considering the semantics of COMMON blocks as well as how they have been employed in legacy code, one should be able to provide similar facilities with entities in a MODULE that are not also part of COMMON blocks when a) there is a companion C processor and b) the entities are variables of a suitable interoperable derived type.

Meaning what fpt and PlusFort can offer with the following

   integer :: n
   real :: x
   common / dat / n, x

should be almost immediately workable with this

module dat_m
   use, intrinsic :: iso_c_binding, only : c_int, c_float
   type, bind(C) :: dat_t
      integer(c_int) :: n
      real(c_float) :: x
   end type
   type(dat_t), bind(C, name=..) :: dat
   ..

That is, the language offers 1-to-1 mapping of COMMON with a “C variable of a structure type” under the conditions of interoperable components of said structure.

@FortranFan - Yes, I think that this is a very good way forward to replace COMMON blocks. Jon Power at Sector7 made a similar suggestion that we could convert COMMON blocks to sequence derived types and pass the address to C. This would also work for any situation where the address association of objects in COMMON is important - for example when replacing DATAPOOL.

It will be easy to implement. It goes on our development list. Thank you.

John

1 Like