Re: Strange Porting Problem CVF to IVF, requesting help and ideas.
Jim Klein <firstname.lastname@example.org> wrote:
> I am thinking Qsave is going to be the immediate "fix". If it is, what
> is the correct fix instead of "Q/save" ?
The "correct" fix is in 2 parts - the save and the initialization. And
it is different enough for common and everything else that I'll separate
the 2 matters.
Actually, if the variables in question are in common, as I think I saw
mentioned (but I've been skimming most of this pretty quickly), you can
get by without the save part. The standard technically requires it and
there have been implementations where it actualy mattered, but I don't
know of any curent implementations where save of common matters. Still,
it is simple enough to do. Just add a statement
I used to (pack when I used common) put this in the include file with th
erest of the declarations of the things in the common, because it needs
to appear everywhere that the common does.
Then to initialize the variables in common....well... the standard
answer involves block data. But that has so many caveats and
complications that I cannot in good faith recommend it. And I sure can't
explain all the issues that it raises here. I recommend instead, doing
any intialization of variables in common with executable statements.
Just use plain old ordinary assignment statements done early in the
program. If there are many of them, you'd probably want to put them in a
subroutine called early in the main program (or anywhere else that you
are sure is before they are needed).
This includes module variables also; they don't have the same issues as
For each variable in question, give it the SAVE attribute, either with a
separate save statement like
or in the trype declaration like
real, save :: x, y
An alternative is to just use an unadorned
with nothing else in the statement (and no other save statements in the
procedure either). This essentially says to save everything that can be
sensibly saved in the routine. It is much like the common compiler
switches, except that this one is in the code instead of on the command
line, and this on eis standard.
Realize, though, that saving alone is not sufficient to make things
initialized. (It might have that effect in some compilers, but it
certainly does not in the standard and is not portable). You have to
also do the initialization. Either
1. Use a data statement, like
2. Use an initializer in the type declaration like
real, save :: x = 0.
3. Or just do it with executable assignment statements.
Technically, initializing with a data statement or an initializer in the
type declaration will also mak ethe variable saved "behind your back",
but I prefer to make the save explicit.
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain