Re: Halt execution procedure



In article <1119476724.264211.51810@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"NuclearWizard" <william.wieselquist@xxxxxxxxx> wrote:

> "But you would never want an AUTOMATIC LOCAL VARIABLE treated this way,
> "initialized" only the first time its procedure is called."

Now that one I would agree with. In fact, automatic variables cannot
have the SAVE attribute at all. However, you have another
misunderstanding, at least in terms of Fortran.

Your variable is *NOT* automatic. It never was - even without the save
attribute. In Fortran, the only kinds of variables that are automatic
are those that have attributes (dimensions or type parameters) specified
by expressions that are not initialization expressions.

Many of the reasons for this are historical. If one were designing a new
language from scratch, many, many things would be different, perhaps
this among them. But the language isn't designed from scratch and it
isn't going to be. If you want to discuss what some theoretical,
nonexistent language might ideally do, well, I suppose that might be an
interesting discussion in some sense, but I'll beg out.

It is *VERY*, *VERY* important in Fortran to understand that the lack of
the SAVE attribute does not make something automatic. The lack of the
SAVE attribute instead means that variables become *UNDEFINED* on all
entries after the first. They neither keep their prior value nor get
reinitialized. Any code that references the value before defining it in
the current invocation is nonstandard. This allows compilers the freedom
to do whatever they like with it. Some compilers (most of them, in fact)
implement it as static. Others might implement it as automatic with
random garbage off the stack as its initial value on subsequent
invocations. Any program that can tell the difference is nonstandard (as
lots of old codes used to be before the initialization-implies-save rule
of f90).

There is no way for you to declare a scalar real variable that is
automatic, regardless of whether it has the save attribute, an
initialization, or anything else. Can't be done in standard Fortran.
Some vendors have an explicit automatic declaration as an extension, and
it has been proposed to add such an extension to the language (which
seems like a reasonable idea to me, but it hasn't been accepted to date).

It might be that you are advocating for the proposal to add an automatic
attribute. If so, I'd think that at least a reasonable proposal.

But if you think that the standard should treat existing code with
initialization as automatic, well... it isn't worth discussing because
it isn't going to happen. Frankly, it doesn't matter what you think. It
doesn't even matter if you are "right" in some abstract sense. The fact
that it would break huge amounts of existing code is far more important
than your (or my) opinion on the matter or any abstract argument. If you
don't think that's more important, well... that doesn't matter either
unless you enjoy tilting at windmills.

Adding a new explicit attribute avoids breaking existing code and is
thus "fair game". You might even garner some support for that.

--
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
.


Quantcast