(j3.2006) (SC22WG5.4130) [ukfortran] Interoperability of dummyarrays

Malcolm Cohen malcolm
Thu Nov 26 19:34:07 EST 2009

> Aleksandar Donev schrieb:
>> Hello,
>> Ok, this is embarrassing, but...I was reading 15.3.6 again and realized I 
>> cannot quite figure this out. What is the C prototype for this interoperable 
>> routine?

There is no unique prototype.

>> subroutine test(n,x,y)

It's not interoperable, because it does not have the BIND(C) attribute.

   SUBROUTINE test(n,x,y) BIND(C)

>>    use iso_c_binding
>>    integer(c_int), dimension(3), intent(in) :: n
>>    real(c_double), dimension(n(1),n(2),n(3)) :: x
>>    real(c_double), dimension(n(1),n(2),n(3),*) :: y
>> end subroutine

Well, one prototype that it interoperates with might be
   void test(int *,double *,double *);
though a better one would be
   void test(int[3],double[],double[]);

I am looking at F2003; note that 15.2.6 item (5) does not require that the dummy 
argument interoperates with the formal parameter, it merely requires that the 
formal parameter be a pointer type and that the dummy argument interoperates 
with "an entity of the referenced type".  So all this requires is that such an 
entity exists, which it surely does (probably a different entity for each 
possible value of n(1:3), but that seems to be no problem).

Reinhold Bader wrote:
>  my impression is that the intent of 15.3.6 is to inductively flatten this 
> into a one-dimensional
>  structure, so
> void test(n[3], x[NPROD], y[]);
>  where NPROD must have the value n(1)*n(2)*n(3)

I don't agree.  The intent cannot have been to deliberately exclude adjustable 
arrays from C interoperability (which requiring the actual dimension to be 
written in would effectively do), that would be crazy.

> (and you strictly speaking need to specify BIND(C) on the
>  subroutine statement).

That's not "strictly"; there are a number of cases where specifying BIND(C) with 
a particular compiler gives you a different ABI in practice, not just in theory.

................................Malcolm Cohen, Nihon NAG, Tokyo.

More information about the J3 mailing list