(j3.2006) Question about lbound of an assumed-rank entity

Daniel C Chen cdchen
Thu Feb 23 11:28:05 EST 2017



Consider the following sample code:

use, intrinsic :: iso_c_binding
integer(c_int) :: arr(2:4)
interface
  subroutine c_sub(arg) BIND(C)
    import
    integer(c_int) :: arg(..)
  end
  subroutine sub(arg)
    integer :: arg(..)
  end
end interface

Print*, lbound(arr, 1)
call c_sub(arr)
call sub(arr)
end

subroutine c_sub(arg) BIND(C)
use, intrinsic :: iso_c_binding
integer(c_int) :: arg(..)
print *, lbound(arg, 1)
end

subroutine sub(arg)
integer :: arg(..)
print *, lbound(arg, 1)
End

Question: Should the output be:
A):
2
0
2

B):
2
1
1

C):
2
1
2

The standard says: (17-007)

[497: 12-15]:
For a C descriptor of an array pointer or allocatable array, the value of
the lower_bound member of each element
of the dim member of the descriptor is determined by argument association,
allocation, or pointer association.
For a C descriptor of a nonallocatable nonpointer object, the value of the
lower_bound member of each element
of the dim member of the descriptor is zero.

[318: 31-36]:
An actual argument of any rank may correspond to an assumed-rank dummy
argument. The rank and shape
of the dummy argument are the rank and shape of the corresponding actual
argument. If the rank is nonzero,
the lower and upper bounds of the dummy argument are those that would be
given by the intrinsic functions
LBOUND and UBOUND respectively if applied to the actual argument, except
that when the actual argument
is assumed-size, the upper bound of the last dimension of the dummy
argument is 2 less than the lower bound of
that dimension.

Based on the above statement, answer A seems to be the correct one...

Thanks,

Daniel

XL Fortran Development, Fortran Standard Representative
IBM Toronto Software Lab
Phone: 905-413-3056
Tie: 969-3056
Email: cdchen at ca.ibm.com
http://www.ibm.com/software/awdtools/fortran/xlfortran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.j3-fortran.org/pipermail/j3/attachments/20170223/e8c63b8a/attachment-0001.html 



More information about the J3 mailing list