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

Daniel C Chen cdchen at ca.ibm.com
Fri Nov 15 15:28:37 UTC 2024


Hi Aury,

Yeah, I came down to the same conclusion that the Note in 8.5.3 probably should include the result of NULL as well to make it allocatable but not a variable.

As for the function result, I also think 15.3.3 is talking about the function result variable within, so may be the title should be “Characteristics of function result variable”.?

There definitely should be some distinction between the result of referencing a function and the function result variable declared in the function definition for sure.

Daniel

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Shafran, Aury via J3 <j3 at mailman.j3-fortran.org>
Date: Friday, November 15, 2024 at 2:25 AM
To: General J3 interest list <j3 at mailman.j3-fortran.org>
Cc: Shafran, Aury <aury.shafran at intel.com>
Subject: [EXTERNAL] Re: [J3] Is NULL(MOLD=allocatable) an allocatable variable?
Daniel & Robert, I am confused by that note. On one hand, it makes sense. It explains why a normal function with an allocatable result can’t directly be passed as an actual arg to another procedure accepting an allocatable argument. On the

Daniel & Robert,

I am confused by that note. On one hand, it makes sense. It explains why a normal function with an allocatable result can’t directly be passed as an actual arg to another procedure accepting an allocatable argument. On the other hand,

15.3.3 Characteristics of function results: “The characteristics of a function result are … whether it is allocatable, …”

At first I thought it must be because 15.3.3 is describing the function result variable -- the thing within the scope of the function itself -- not the data entity that is the result of execution of the function. But then I found:
5.4.3.1 General: “A data entity that is the result of the execution of a function reference is called the function result.”
So those characteristics of 15.3.3 are describing the result of the execution of the function. And the characteristics include whether the result is allocatable. That seems to directly contradict the note in 8.5.3. The only thing I see that might resolve the contradiction is:

15.5.3 Function reference: “When execution of the function is complete, the value of the function result is available for use in the expression that caused the function to be invoked.”

It does not say the “function result” is available for use, but only the “value of the function result”. So maybe the expression of the function reference becomes nothing more than a value, stripped of all characteristics. But that would imply it also does not have characteristics like type and shape, which seems wrong.

The NULL intrinsic says its “result” is an allocatable entity, but it doesn’t specify a “result value”. If all the NULL function reference becomes is a value stripped of any characteristics, then the description of the result of NULL is meaningless, which can’t be right. Assuming that the entire data entity and all its characteristics as a function result are available to the “expression that caused the function to be invoked”, which is the only interpretation which makes any sense to me, then I think the code Danial gave is conforming.

The only thing which contradicts that interpretation is the note in 8.5.3, but notes are not prescriptive. If anything, the note should be changed to say “Only variables, components, and the result of the NULL intrinsic function can have the ALLOCATABLE attribute.” Also, I’m interested to know how the apparent contradiction between the note and the characteristics described in 15.3.3 is resolved.

Thanks,
Aury

From: J3 <j3-bounces at mailman.j3-fortran.org> On Behalf Of Robert Corbett via J3
Sent: Thursday, November 14, 2024 7:19 PM
To: Daniel C Chen via J3 <j3 at mailman.j3-fortran.org>
Cc: Robert Corbett <rpcorbett at att.net>
Subject: 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

      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<mailto: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/9837ad79/attachment.htm>


More information about the J3 mailing list