This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
gfortran feature request: internal procedures as actual arguments
- From: Bill Paxton <paxton at kitp dot ucsb dot edu>
- To: fortran at gcc dot gnu dot org
- Date: Sun, 29 Jul 2007 19:00:19 -0700
- Subject: gfortran feature request: internal procedures as actual arguments
Hello,
This is a plea for gfortran to support internal procedures as actual
arguments.
I'm working on the development of a set of modules for experiments in
astrophysics
("mesa": http://mesa.sourceforge.net/), and the main problem with
making clean, general,
thread-safe packages can be easily solved using internal procedures
as arguments.
I've attached a tiny example to illustrate the problem and its solution.
Attachment:
test.f
Description: Binary data
The general pattern is that one module, mod1, provides a routine such
as a root finder
or an ODE solver that takes a procedure argument (such as a
derivative evaluator).
A second module, mod2, provides some complex functionality that uses
derived types to
hold state information. Some of the operations in mod2 need to use
the routine in mod1.
The procedure arg that the mod2 routine passes to mod1 will need to
access information
from an instance of the derived type. The problem is how it will get
hold of a pointer
to the target record. I want mod2 to avoid using globals -- to be
thread-safe without
requiring critical sections, to allow use as a dynamic library, and
because it just good
programming practice. ; - )
With internal procedures as arguments, the solution is trivial -- the
pointer is stored in
the local variables of the parent routine, so it is accessible to the
internal procedure
when it is called from the mod1 routine.
Without internal procedures, the "solution" seems to be to give up
and use globals.
Along with that comes the requirement for critical sections or some
such to remain
thread-safe. And you know the issues about globals and dynamic
libraries.
At least one compiler out there already supports this feature (the
Intel one),
but for obvious reasons it would be so much better if gfortran
supported it!
I hope it makes it onto your TO-DO list. I need it yesterday!
Cheers,
Bill Paxton
http://theory.kitp.ucsb.edu/~paxton/