On 3/3/21 5:41 AM, JCampbell wrote:
> On Wednesday, March 3, 2021 at 10:03:42 PM UTC+11, gah4 wrote:
>> On Wednesday, March 3, 2021 at 12:02:48 AM UTC-8, Ron Shepard wrote:
>>
>> (snip on SAVE and initialization)
>>>> I don't find it controversial.
>>>> Prior to F90, there were data statements that had the same effect.
>>>> Many "first call" approaches rely on the difference between "real :: y = 0" and "real :: y ; y = 0"
>>> In F77, if a data statement was used to initialize an unsaved local
>>> variable, and if that value was changed during execution, then its value
>>> on subsequent entry to that subprogram was undefined. It was only if the
>>> value was unchanged during execution that its value was defined to have
>>> that same value upon subsequent entry to that subprogram. I assume that
>>> undefined nature was a carryover from the earlier f66 standard -- I do
>>> not think that was introduced just in f77, otherwise it would have
>>> changed existing legal code to be illegal.
>> As well as I know it, f66 has it undefined to allow for overlays, and f77 to
>> allow for automatic allocation.
>>
>> From the beginning, Fortran used static allocation but, as far as I know,
>> never said that anywhere. I am not so sure when overlays came along,
>> but were reasonably common by f66 times.
>>
>> By f77, many systems used automatic allocation. As noted, the f66
>> rules were not incompatible with it, and SAVE was added.
>
> The functionality of data/save variables has been required for the random number generators that I written in FORTRAN and have used.
If so, then you were depending on the behavior of a specific compiler,
not on the semantics specified by the language standard. The standard
conforming way to "save" a variable before f77 was to put it in a common
block. It was not uncommon to see named common blocks with single
variables in them, often with oddball names in the attempt to avoid
linker symbol conflicts, to save the values of variables that were
otherwise local. f77 introduced SAVE, which could be used for either
common blocks or for local variables, and that allowed many
nonconforming dusty deck codes that relied on static variables to be
modified and to become standard conforming. But for the present
discussion, f77 did not have "automatic save" of any variables, whether
associated with DATA statements or not. Even common blocks were allowed
to go out of scope in f77 if they were not saved. The SAVE attribute had
to be specified explicitly to be conforming.
> I can't recall using a compiler that did not support this functionality.
Yes, I know. It was not uncommon to depend on static allocation of
variables or of common blocks, especially before f77, but also
afterwards with dusty deck code. But that behavior was not required by
the f66 standard, and f77 introduced SAVE specifically for that purpose.
> My recollection is that DATA implied a saved variable in all F77 compilers I used on PC, Apollo/Sun and Pr1me/Vax.
Yes, likely all variables were static in those compilers, but it was not
required by the standard.
> Those I used all supported a first call approach and retained the value, implied by the use of a DATA statement. There were many other F77 compilers I did not use.
> It is difficult to remember any F77 compilers that performed different to as I recall. (ICL or IBM ?)
If you used an overlay linker, then you could have several copies of a
named common block or of a subroutine with its own local variables, each
with its own set of saved values. I experimented enough to do that a few
times and get things to work, but when I was writing code designed to
run on more than one machine, I avoided doing it.
> I did use Lahey LF77 Fortran (640k) with an overlay linker. The retention of saved variables may have depended if the routine went out of scope, although the linker could have retained all static variables in scope. The days of reviewing the load map !!
> Ron, what compilers have you used that suggest the controversy ?
You are mistaken about what the controversy is. The controversy is the
introduction of implied save, which I think occurred in f95. Many
programmers, myself included, would have preferred that the SAVE
attribute be required for initialized variables, and also that the
compiler would have been required to diagnose the missing SAVE attribute
and warn the programmer (at compile time, not run time).
> The concept that "otherwise it would have changed existing legal code to be illegal" was not as strictly interpreted prior to F90/95 as most compilers had their own extensions.
> Portability was a big issue prior to F90 which was a significant success of F90.
> Am I correct to assume that F90+ standard supports the "first call" difference between "real :: y = 0" and "real :: y ; y = 0" ?
I'm not certain, but I think f90 left the situation undefined, the same
as f77, but now extended also to initialization on the declaration line
which was the new syntax. in other words, the value on subsequent entry
to the subprogram was only defined when it had not been changed during
previous executions. Then f95 introduced the implied save, which, as we
can see by this discussion, has been a confusing feature for some 25
years, and will continue to be a confusing feature in the future,
especially now that all subroutines have also an implied RECURSIVE
attribute. As I said previously, I do not think that feature will ever
be changed because it would now invalidate too much existing code that
depends on implied save. At this point, I regard it as a mistake in the
language that we all must continue to tolerate indefinitely and to
discuss endlessly.
$.02 -Ron Shepard