(j3.2006) Question about lbound of an assumed-rank entity
Bill Long
longb
Mon Feb 27 08:58:47 EST 2017
On Feb 27, 2017, at 7:35 AM, Bader, Reinhold <Reinhold.Bader at lrz.de> wrote:
> 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.
When calling a procedure with BIND(C) a Fortran caller does not know what language was used to write the callee. What it does know is that the BIND(C) callee uses the C calling conventions. So the callee will get the address of a C descriptor as the incoming argument. Even if it was written in Fortran.
Cheers,
Bill
> (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
> http://www.ibm.com/software/awdtools/fortran/xlfortran
>
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3
Bill Long longb at cray.com
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
More information about the J3
mailing list