Re: best way to use the USE statement
- From: Ron Shepard <ron-shepard@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Aug 2006 00:07:47 -0500
In article
<Q9qJg.11410$5i3.7756@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"James Giles" <jamesgiles@xxxxxxxxxxxxxxxx> wrote:
I'd agree with you *if* I could control host association. As it
is, there are cases where one is more legible, and there are cases
where the other is.
This reminds me of a subtle point about variable scope.
I was experimenting a while back with these two approaches. Suppose
you have a variable I in one of the modules. If you USE that module
from within another module, then you can declare a local variable I
in a subroutine and you get no compiler warning about the possible
conflict (the local variable is referenced). However, if you move
the USE statement to within the subprogram, then you get a compiler
error because of the conflict between the module variable and the
local variable with the same name. To avoid this conflict, you must
include a rename clause on the USE statement. In some ways, that is
a good thing because it makes explicit which variable is being
referenced.
I think lately I'm tending more toward having the USE statements
within the subprograms, with ONLY and rename clauses when
appropriate. This also has the advantage of being able to quickly
see exactly where these imported variables come from.
$.02 -Ron Shepard
.
- References:
- best way to use the USE statement
- From: Kamaraju Kusumanchi
- Re: best way to use the USE statement
- From: Richard E Maine
- Re: best way to use the USE statement
- From: James Giles
- best way to use the USE statement
- Prev by Date: Re: Scope of implied-do index
- Next by Date: Re: Reading Cray binary on linux
- Previous by thread: Re: best way to use the USE statement
- Next by thread: Fortran for new and old Macs on OS X
- Index(es):