[J3] Is NULL(MOLD=allocatable) an allocatable variable?
Daniel C Chen
cdchen at ca.ibm.com
Fri Nov 15 01:47:10 UTC 2024
Hi Aury,
Thanks for the response.
Yeah, it was a bad example to use ALLOCATE statement as the syntax rule indeed disqualify my usage as well as intrinsic assignment.
However, I think the question about if “allocatable entity” is an allocatable variable remains.
I agree that as the standard is written now, “allocatable entity” means an entity with the ALLOCATABLE attribute. The standard also says only variables and components can have the ALLOCATABLE attribute, which makes “NULL(MOLD=allocatable)” a variable.
As for the allocatable function result, I think the allocatable result variable itself is a variable, but the result of referencing such a function does not have the ALLOCATABLE attribute, so it is not an “allocatable entity”.
As for the structure constructor case you have, because `component-data-source` can be `expr` so it is slightly different from the actual argument case in my example.
I am also in agreement that the code I have is conforming because of the above reasoning seemed conclud an “allocatable entity” is an allocatable variable.
Probably like the ALLOCATE statement and the intrinsic assignment, the syntax rules indeed prohibit this usage elsewhere a variable can appear.
Daniel
From: Shafran, Aury <aury.shafran at intel.com>
Date: Thursday, November 14, 2024 at 5:05 PM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Daniel C Chen <cdchen at ca.ibm.com>
Subject: [EXTERNAL] RE: Is NULL(MOLD=allocatable) an allocatable variable?
Daniel, > If so, it will make “ALLOCATE(NULL(MOLD))” a conforming code, which doesn’t seem right. That is not conforming regardless of the definition of allocatable entity, because an <allocate-object> to an ALLOCATE statement must
Daniel,
> If so, it will make “ALLOCATE(NULL(MOLD))” a conforming code, which doesn’t seem right.
That is not conforming regardless of the definition of allocatable entity, because an <allocate-object> to an ALLOCATE statement must be a <variable-name> or a <structure-component>:
R934 allocate-object is variable-name
or structure-component
NULL(MOLD) is not a variable name or structure component, so it’s not allowed in an ALLOCATE statement.
> what does “allocatable entity” mean? Can an “allocatable entity” have no ALLOCATABLE attribute?
The definition of “allocatable” is in the Terms and Definitions, 3.2. “having the ALLOCATABLE attribute”. So an “allocatable entity” would be any entity with the ALLOCATABLE attribute. So no, an “allocatable entity” cannot *not* have the ALLOCATABLE attribute.
> Does “allocatable entity” mean allocatable variable as the standard also says only variables and components can have the ALLOCATABLE attribute.
An example of an allocatable entity that is not a variable would be a function result with the ALLOCATABLE attribute. A non-pointer function result is not a variable, per R902 and C902. But the result of a function can certainly be allocatable, and so it would be an allocatable entity but not an allocatable variable. NULL(MOLD) , where MOLD is something allocatable, would also fall under the category of allocatable function result.
Another example of an allocatable entity that is not a variable, albeit much less useful, is a constant derived type object with a allocatable component, e.g:
type :: t
integer, allocatable :: a
end type
type(t), parameter :: c = t(NULL())
end
Such a component, as a subobject of the constant, would not be a variable (C901) because it is not definable.
> Is the following code conforming?
Unless there’s something subtle I’m missing, I believe that code is conforming, yes. As invoked, ‘arg’ would be unallocated.
As an example though, it would not be conforming if ‘arg’ were INTENT(OUT) because the actual argument is not a variable, and is not definable.
Thanks,
Aury
From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Daniel C Chen via J3
Sent: Thursday, November 14, 2024 4:22 PM
To: Van Snyder via J3 <j3 at mailman.j3-fortran.org>
Cc: Daniel C Chen <cdchen at ca.ibm.com>
Subject: [J3] Is NULL(MOLD=allocatable) an allocatable variable?
The standard describes the argument and the result of intrinsic NULL(MOLD) when MOLD is an allocatable variable as
“
Argument. …If MOLD is allocatable its allocation status may be allocated or unallocated. It need not be defined with a value.
Result Characteristics. If MOLD is present, the characteristics are the same as MOLD….
Result. The result is a disassociated pointer or an unallocated allocatable entity.
“
Does “allocatable entity” mean allocatable variable as the standard also says only variables and components can have the ALLOCATABLE attribute.
If so, it will make “ALLOCATE(NULL(MOLD))” a conforming code, which doesn’t seem right.
If not, what does “allocatable entity” mean? Can an “allocatable entity” have no ALLOCATABLE attribute?
Is the following code conforming? It really depends on the answer of the above question.
“
real, allocatable :: ra
call sub(NULL(ra))
Contains
Subroutine sub(arg)
real, allocatable :: arg
…
end subroutine
end
“
Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20241115/596dd809/attachment-0001.htm>
More information about the J3
mailing list