[J3] Is NULL(MOLD=allocatable) an allocatable variable?

Shafran, Aury aury.shafran at intel.com
Thu Nov 14 22:04:58 UTC 2024


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/20241114/dcd883b2/attachment.htm>


More information about the J3 mailing list