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

Daniel C Chen cdchen at ca.ibm.com
Fri Nov 15 01:50:52 UTC 2024


Thanks Bob.
Yeah, if the reasoning Aury and I discussed makes sense, the code should be conforming.

Daniel

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Robert Corbett via J3 <j3 at mailman.j3-fortran.org>
Date: Thursday, November 14, 2024 at 7:19 PM
To: Daniel C Chen via J3 <j3 at mailman.j3-fortran.org>
Cc: Robert Corbett <rpcorbett at att.net>
Subject: [EXTERNAL] Re: [J3] Is NULL(MOLD=allocatable) an allocatable variable?
In the text that follows, all references to parts of the Fortran standard are with respect to J3/24-007. In the standard as written, the value of a function reference does not have the ALLOCATABLE attribute. The NOTE in Subclause 8. 5. 3 states

In the text that follows, all references
to parts of the Fortran standard are with
respect to J3/24-007.

In the standard as written, the value of
a function reference does not have the
ALLOCATABLE attribute.  The NOTE in
Subclause 8.5.3 states

      Only variables and components can
      have the ALLOCATABLE attribute.
      The result of referencing a
      function whose result variable
      has the ALLOCATABLE attribute is
      a value that does not itself have
      the ALLOCATABLE attribute.

Intrinsic functions are magic entities
that do not necessarily follow the
general rules of the standard.  The
description of the Result of the
intrinsic function NULL (16.9.155)
says that the result of the function
can be "an unallocated allocatable
entity".  Because the language does
not include allocatable procedures,
the unallocated allocatable entity
must be a data entity.  I suspect
that it was intended to be a data
object, but that is not obvious
from the text.

A strict reading of the standard as
written makes the example you gave
nonconformant.  I believe that the
intent of the committee at the time
Fortran 2003 was produced was to
allow your example.  I suspect that
an interp is needed.

Robert Corbett


On Thursday, November 14, 2024 at 01:21:59 PM PST, Daniel C Chen via J3 <j3 at mailman.j3-fortran.org> wrote:





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/86fd029b/attachment.htm>


More information about the J3 mailing list