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

Bader, Reinhold Reinhold.Bader
Mon Feb 27 08:35:06 EST 2017


Hello all,

The answer I arrive at for the program output is

D)
2
2
2

I believe the first paragraph cited below only applies to an implementation of c_sub in C. An implementation in Fortran does
not expose the C descriptor.
(Whether it was a good idea to *not* remap bounds for the nonpointer case of an assumed rank array within Fortran is a separate issue ...)

Cheers
Reinhold

Von: j3-bounces at mailman.j3-fortran.org [mailto:j3-bounces at mailman.j3-fortran.org] Im Auftrag von Daniel C Chen
Gesendet: Donnerstag, 23. Februar 2017 17:28
An: j3 at mailman.j3-fortran.org
Betreff: (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/20170227/6eb31ff5/attachment.html 



More information about the J3 mailing list