Tim Springer <Tim.Sp...@PosiTim.com.invalid> wrote:
> > Unless you are restricting your code to f2008 compilers (none of which
> > exist), you should specify the SAVE attribute and the compiler is
> > correct to complain about your failure to do so.
>
> However, it seems most compilers make module variables
> SAVE by default....
I would not say that was accurately stated. Instead, I'd say that most
(all, to my knowledge) compilers implement modules in such a way that
unsaved variables act just like saved ones. The distinction is perhaps
nitpicky, but it does show up in things like you observed. The variables
don't actually have the SAVE attribute, which is why you get the
complaint. The standard requires the capbability for a compiler to
diagnose that problem. That requirement does not depend on whather
unsaved variables "might as well be saved" because they act the same for
all practical purposes. It depends on whether they have the SAVE
attribute.
> > As noted above, there is no "NULLIFY" in the code, but the default
> > initialization is fine as of f95, provided you use the SAVE attribute.
> > Default initialization was not a feature of the f90 standard at all; it
> > was one of the fairly few things introduced in f95.
>
> Hmm, I seem to have another gap in my knowledge here. Your remarks seems to
> indicate that there is a difference between a statement like:
> somepointer => NULL()
>
> and
> NULLIFY(somepointer)
>
> I know that "NULLIFY" can not be used for default initialization. But are
> there more differences?
As I mentioned in the part you elided, it is mostly a nitpick of
terminology, starting with the fact that you called the default
initialization a statement. It isn't. It is part of another statement.
"Statement" is a technical term in the language, and it is a term that
comes with a lot of "baggage", none of which really applies to the code
you had. For example, a statement can have a statement label. Lots more
like that. Hard for me to elaborate everything. It is sort of like you
had called it a subroutine. It just isn't one. You can write subroutines
that nullify pointers, and even subroutines that have NULLIFY statements
in them, but that doesn't mean an initialization or a NULLIFY statement
is a subroutine.
There is a pointer assignment statement that can look like
somepointer => NULL()
but initialization or default initialization do not involve that
statement. They use a syntax that looks like a restricted form of that
statement, but that doesn't mean they are that statement. Hard for me to
sit does and list the differences, particularly as many of them are so
trivial that it seem sto me that they aren't worth listing, but I can't
tell which ones you might have the same judgement about. The bit about
not allowing a statement label is pretty high on the list of "well duh"
differences that I'd guess you also would not really consider worth
mentioning, but other things are less obvious.
For example, you can use bounds remapping in a pointer assignment
statement, but not in an initialization. If this were not a pointer
case, a non-obvious difference would be that defined assignment never
applies to initializations; they always act like intrinsic assignment.
But default assignment doesn't apply to pointer assignment anyway.
And very relevant is that calling initialization a statement helps
confuse some people into thinking that it actually is an assignment
statement that just happens to be tacked onto the syntax of the type
declaration. This encourages confusions like the expectation that it
would be "executed" at the beginnning of each call to the subroutine;
after all, that's what would happen with an assignment statement.
Or perhaps you could just write it all off to me being a stickler for
terminology. Making sure that terminology was used correctly was part of
my job as editor of the standard. (Not that I did it perfectly, but it
was part of my job). It is important for a standard to say exactly what
it means instead of somnething that is "sort of simillar - enough so
that people ought to get the idea."