(j3.2006) Clarification related to C interoperability

Bill Long longb
Tue Feb 10 16:50:16 EST 2015


On Feb 10, 2015, at 10:21 AM, Menard, Lorri <lorri.menard at intel.com> wrote:

> In TS 29113, on the section titled CFI_cdesc_t, there is the following description:
>  
> ---
> 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.
> ---
>  
> Here?s my question; does the attribute of the array apply to the actual argument or to the dummy argument?
>  

The descriptor that is passed has to match the expectations of the dummy argument.  The C function that is called would be written only one way, assuming the descriptor represented an object with the characteristics of the dummy argument.   This is the same thing that happens in ?old? Fortran if the dummy is assumed-shape, and the actual is allocatable.  The subprogram sees a dope vector for an assumed-shape array.  The caller sees the interface and provides the correct descriptor based on the declaration of the dummy.


> For example:
>  
> Program call_c
>  
> Interface
>    Subroutine print_values (int_array) bind (c)
>    Integer, dimension(..) :: int_array
>    End subroutine print_values
> End interface
>  
> Integer, allocatable :: alloc_array
> Integer :: static_array(10)
>  
> Allocate(alloc_array(-1:8))
>     ?
> Call print_values(alloc_array)
>  
>  
> Is the lower-bound for dim[0] of the C-Descriptor created for the call to ?print_values? given the value 0, or the value -1?

0

>  
> Clearly, if the call were ?call print_values(static_array)? then the lower-bound for dim[0] would be 0.

yes. 

>  
> If the program were changed to this:
>  
> Program call_c2
>  
> Interface
>    Subroutine print_values (int_array) bind(c)
>    Integer, allocatable, dimension(..) :: int_array
>    End subroutine print_values
> End interface
>  
> Integer, allocatable :: alloc_array
> Integer :: static_array(10)
>  
> Allocate(alloc_array(-1:8))
>     ?
> Call print_values(alloc_array)
>  
>  
> Clearly, the lower-bound for dim[0] would be given the value -1.

yes.

>  
> If the call were ?call print_values(static_array)? I would expect a compile-time error.

yes. 

>  
> Other opinions?

no.

Cheers,
Bill


>  
>                 Thanks ?
>  
>                                                 --Lorri
>  
>  
>  
>  
> _______________________________________________
> 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 Suport  &                                  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