On 2020-01-11 11:27, FortranFan wrote:
> On Thursday, January 9, 2020 at 4:19:26 PM UTC-5, Ian Harvey wrote:
>
>> ..
>>
>> The definition of local variable is in 3.154.2 of F2018.
>>
>> variable in a scoping unit that is not a dummy argument or part
>> thereof, is not a global entity or part thereof, and is not an
>> entity of part of an entity that is accessible outside that scoping
>> unit.
>>
>> The object created by allocation of a pointer does not meet that
>> definition - it is not a "variable in a scoping unit" (noting that
>> scoping unit is a source concept, not an execution concept),
>> further it is (or can be, if you want to avoid circular definition)
>> also accessible outside the scoping unit that is the subprogram
>> xalloc.
>>
>> Because the object created by allocation of a pointer does not meet
>> the definition of a local variable, it is not a local variable.
>
>
> Thank you for your effort, but I think the standard does not support
> your reasoning.
>
> The standard does state "Allocation of a pointer creates an object
> that implicitly has the TARGET attribute." It really does not
> clarify anything else about this "object".
>
> Then section 3.46 of the standard suggests an object can be "constant
> (7.1.4), variable (9), or subobject of a constant (5.4.3.2.4)". If
> one leaves out "constant" or "subobject of a constant", one can think
> an object is a variable.
It is a variable, as all things with the TARGET attribute are.
> Then one can take 3.46 to mean "the object created by allocation of a
> pointer" is a variable of some sort.
>
> But now section 19.1 para 1 says, "An entity is identified by an
> identifier".
>
> The standard does not indicate "the object created by allocation of a
> pointer" to have an identifier. Should one would think if the
> standard doesn't give the object an identifier one should assume it
> is NOT "identified by an identifier" If so, it must follow this
> variable which is "the object created by allocation of a pointer" is
> not an entity on account of not having an identifier.
>
> If the variable which is "the object created by allocation of a
> pointer" is then not an entity, it cannot then be "a global entity or
> part thereof" and it cannot be "an entity of part of an entity that
> is accessible outside that scoping unit".
The term "entity" (without further qualification) has its common
language use. It is just a fancy way of saying "thing".
Entities within a Fortran program do not always have identifiers. A
simple case is a Fortran main program without a name.
The object created by allocation of a pointer is an entity.
The object created by allocation of a pointer does not appear in the
list of things that are considered global entities, therefore it is not one.
It is trivial to construct examples where the object created by
allocation of a pointer is accessible outside of the scoping unit that
has the ALLOCATE statement, but this starts down the rabbit hole of what
"accessible outside" means ("accessible outside" wording is to knock out
host and use association *into* the scoping unit). Rather than run down
that rabbit hole, see below.
> So then one is left wondering in the context of 3.154.2 whether it is
> a "variable in a scoping unit that is not a dummy argument". May be
> it is, or may be not.
A scoping unit is a piece of source. You can print out the source for a
program and use a highlighter, scissors or similar to delineate a
scoping unit (bear in mind there may be holes due to nesting of scoping
units). If you look at that scoping unit you will not see the object
created by allocation of a pointer, because that is not a source
concept, it is something that arises dynamically from execution of the
source.
Whether something is a local variable or not is a simple question of
source, not of execution.
> This goes back to your recent comment in the other thread
>
https://groups.google.com/d/msg/comp.lang.fortran/9_0q0dBRzpk/6bvW3ehiAQAJ.
> What may be clear to you in this context "is .. not .. obvious". For
> anyone then to keep insisting there are no problems with the
> description in the standard when it comes to the target of 'q' with
> the code in the original post is doing a disservice to Fortran.
Don't be silly. "I disagree with your interpretation" is not the same
thing as "the wording of the standard does not require improvement".
Submit an interpretation request if you want. That clause of the
standard is notorious for requiring edits.
But INTENT attribute aside, the behaviour expected in the original post
of this thread was the intent of the authors of Fortran 90 and
subsequent standards, so a fair bit of remedial work to section 4.3 of
F2018 will be required to support your argument that this is not
conforming. Lots of code previously considered conforming would be
broken - expect pitchforks!