by nospa » Sat, 28 Jul 2007 04:57:11
enR < XXXX@XXXXX.COM > wrote:
Definitely. That's the easy and "obvious" way in f90.
Correct. COMMON can only have variables. Parameters aren't variables.
Basically, a parameter might not even exist in memory at run-time. It is
a compile-time concept. In many situations, the value of the parameter
will also end up somewhere in memory. For example, if you pass it as an
actual argument, there will need to be a memory location for that actual
argument; but in some sense, that location is just a temporary copy of
the value of the parameter, rather then being the parameter itself.
Yes, that would be what to do if you are stuck with Fortran 77, except
for some minor quibbles, namely
USE is what you do with modules. I might have thought you meant to "use"
it in a more generic sense, but your capitalization sure makes it sound
like you mean a USE statement. A USE statement is only for modules and
will not be found in any f77 compiler, even as an extension.
What you can do in most f77 compilers is INCLUDE a source file. INCLUDE
is not strictly f77 either, but almost all f77 compilers that you are
likely to run into these days have it as an extension. Some earlier f77
compilers didn't, but they are not compilers that you are likely to
find. The term "header file" isn't really a Fortran term, though the
concept is understood and some people probably call them that. You are
more likely to see them called something like "include files", though it
is the same concept.
One thing important to understand about include files (or header files)
is that it is purely a textual inclusion of the source code. There is no
particular connection between different scoping units just because they
include the same files. In particular, declaring a variable in an
include file does not magically make it the same variable in all places
that include the file. Likewise, when you declare a parameter in an
include file, you will in some sense have a different parameter (of the
sam ename) in each scoping unit that includes the file. But all these
different parameters will have the same value, so the distinction is
mostly academic.
One question is whether you actually need the things in question to be
paameters. Perhaps you do; I don't have enough data to tell. If they
don't have to be parameters, then there are other options.
The gory details of initialization expressions are messy and, for the
most part, you don't need to know them, but can just remember the
principle that they must be known at compile time.
A lot of people get tripped up by the fact that the statement
integer x
doesn't mean that x is a variable. I find it an unfortunate and
historical oddity that Fortran doesn't actually have a direct way of
declaring something to be a variable. The only ways are indirect, such
as declaring an attribute that only a variable can have (SAVE comes to
mind, but it isn't allowed in all cases), or most commonly, just by not
declaring that it is something other than a variable. I would prefer at
least the option of a direct and positive declaration rather than the
indirect or negative forms available.
That declaration means only that x, whatever it is, has type integer. X
might be a variable, a parameter, or a function. I think those are the
only possibilities.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience come