Re: MODULEand USE versus Argument Passing



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

.



Relevant Pages

  • Re: Reentrancy
    ... defines "reentrant" gives 6 rules to write reentrant code. ... char reentrant_func ... In call-2 we supplied a pointer to a global data so the function ... if a function that uses a global variable is non-reentrant because ...
    (microsoft.public.vc.language)
  • Re: Reentrancy
    ... defines "reentrant" gives 6 rules to write reentrant code. ... char reentrant_func ... In call-2 we supplied a pointer to a global data so the function call ... global variable is non-reentrant because value of the varible can be changed ...
    (microsoft.public.vc.language)
  • Re: INVALID_HANDLE_VALUE vs. NULL
    ... Sometimes a HANDLE is not a pointer. ... of zero started for MS, it was an index to a table. ... >> value for invalid handles. ... > program with NULL in a structure pointer would trash the low memory area ...
    (microsoft.public.win32.programmer.kernel)
  • Re: question on static variable in a function
    ... Whenever a function returns a pointer, ... static char retbuf; ... since a function using static data is not ... My question is what "reentrant" means here? ...
    (comp.lang.c)
  • question on static variable in a function
    ... Whenever a function returns a pointer, ... This fix is imperfect, since a function using static data is not ... My question is what "reentrant" means here? ...
    (comp.lang.c)