(j3.2006) Question about lbound of an assumed-rank entity
Steidel, Jon L
jon.l.steidel
Thu Feb 23 12:09:37 EST 2017
I would agree that A is the correct answer (2 0 2).
-jon
From: j3-bounces at mailman.j3-fortran.org [mailto:j3-bounces at mailman.j3-fortran.org] On Behalf Of Daniel C Chen
Sent: Thursday, February 23, 2017 11:28 AM
To: j3 at mailman.j3-fortran.org
Subject: (j3.2006) Question about lbound of an assumed-rank entity
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<mailto: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/4acfe1f3/attachment.html
More information about the J3
mailing list