Regarding implicit SAVE,
You have a good point about the program unit, where the concept of SAVE is redundant. This situation already occurred in f77 with COMMON blocks. Common blocks in the main program did not need to be saved, while those appearing at other places where they could go out of scope did require a save statement (at least in some cases, it was a complicated issue). SAVE was introduced in f77. Before that, everything, common blocks and local variables, basically either had save semantics or their status was undefined by the language. SAVE was introduced to clarify the differences.
However, as you say, consistency with the rest of the language should probably be the determining factor. It would be simpler for both compiler writers and programmers to know just one simple rule, rather than to separate off some of the redundant cases.
IMHO there is no good fix to the (obvious I guess) error that was made introducing implicit
SAVE
attribute in the declarations with initializers. What has come to my mind is maybe we could addUNSAVE
declaration/attribute, similarly toSAVE
. Then, addingUNSAVE
declaration without any list of objects would allow to useINTEGER :: par=23
legally, without implicitSAVE
attribute. Alternately, one could writeINTEGER, UNSAVE :: par=23
I donāt think Iām in favor of UNSAVE or NOSAVE or any of that. That is all extra baggage for compiler writers to support and for programmers to understand. It is just a complicated way to do something that is already clear and straightforward in the language, namely a simple executable statement.
par = 23
Also, as a matter of style, it is often better to have such initializations in the code as executable statements rather than in the declaration statement. Consider the computation of, say, a summation over elements.
real, nosave :: sum=0.0
do i = 1, n
sum = sum + something
enddo
In that case, everything is visible and it is clear what is supposed to happen. But what if there are a few dozen lines of code in between. Then you have to scroll back to see if it was initialized, and what it was initialized too. But if the initialization is done as an executable statement right there, then everything you need to know is localized.
sum=0.0
do i = 1, n
sum = sum + something
enddo
That first way is not always best, even if NOSAVE were available. And of course, in current fortran where there is no NOSAVE attribute, that first way is almost certainly an error because of implicit save.