[J3] [EXTERNAL] [BULK] Are array bounds of an allocatable function result persistent?

Van Snyder van.snyder at sbcglobal.net
Fri Feb 7 20:41:50 UTC 2025


On Fri, 2025-02-07 at 18:34 +0000, Clune, Thomas L. (GSFC-6101) via J3
wrote:
> I believe the question comes down to whether `foo()` is an expression
> or a whole array.   To my understanding it is an expression and not a
> whole array, but … could not readily find where that is stated. 
>    Thus, I expect:  `1 3`.   NAG & GCC provide that output for what
> it is worth.

The function result VARIABLE is allocatable, but the function result
isn't, so it doesn't have the usual allocatable "descriptor" under the
covers to drag around its bounds. So I would expect 1, 3 to be printed.

In

program foo

  integer :: A(10) = [1,2,3,4,5,6,7,8,9,10]
  print '(i0,", ",i0)', lbound(a(4:6),1), ubound(a(4:6),1)

end program foo

Intel and NAG both compile without messages and print "1, 3"

> Hello,
> 
> Consider the following code:
> 
> ```
> print*, lbound(foo())
> print*, ubound(foo())
> contains
>   function foo()
>    real, allocatable :: foo(:)
>    allocate(foo(4:6))
>    foo = 1.0
>   end
> end
> ```
> 
> Should the out be 
> 4
> 6
> 
> or
> 1
> 3
> 
> I would expect 4, 6 but couldn’t’ find any wording in the standard
> that specifies one way of the other..
> 
> Thanks,
> Daniel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250207/5ed0c2a0/attachment-0001.htm>


More information about the J3 mailing list