Re: MODULEand USE versus Argument Passing
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Wed, 29 Jun 2005 17:01:38 -0700
John Harper wrote:
In article <d9us2s$ncr$1@xxxxxxxxxxxxxxxxxx>, E. Robert Tisdale <E.Robert.Tisdale@xxxxxxxxxxxx> wrote:
Global variables are *always* a bad idea. Never pass function arguments through modules or common storage.
Really? Suppose I am using one of the NAG routines, e.g. d01akf, to calculate integral from a to b of f(x,y) dx for various values of y. The NAG specification says (irrelevant detail omitted; and REAL should be replaced by REAL(kind(1.0d0)) with many compilers)
(snip)
and f must be declared as EXTERNAL in the (sub)program from which d01akf is called, and it must be declared as a REAL(DP) function of one REAL(DP) variable, not two.
I had thought the way to get y into f was by COMMON before f90, and by using a module nowadays. What would Robert have me do?
Not to agree with Robert (I don't) but I don't believe this is the best solution. It is the Fortran solution since Fortran I, though. Note, though, that it isn't reentrant.
(Much of the standard C library isn't reentrant either, but I don't think I will have much say in changing it.)
In C I would add an additional parameter which is a void pointer
such that one could pass a structure pointer through to the called routine. That allows for a reentrant solution, pointers to different structures being passed as needed.
I don't know that there is a Fortran solution similar, though.
-- glen
.
- References:
- MODULEand USE versus Argument Passing
- From: Herman D . Knoble
- Re: MODULEand USE versus Argument Passing
- From: E. Robert Tisdale
- Re: MODULEand USE versus Argument Passing
- From: John Harper
- MODULEand USE versus Argument Passing
- Prev by Date: Passing a 2 dimensional array from fortran to c++
- Next by Date: Re: Passing a 2 dimensional array from fortran to c++
- Previous by thread: Re: MODULEand USE versus Argument Passing
- Next by thread: Re: MODULEand USE versus Argument Passing
- Index(es):
Relevant Pages
|