From owner-sc22wg5@open-std.org  Fri Nov 27 01:33:41 2009
Return-Path: <owner-sc22wg5@open-std.org>
X-Original-To: sc22wg5-dom8
Delivered-To: sc22wg5-dom8@www2.open-std.org
Received: by www2.open-std.org (Postfix, from userid 521)
	id DDFB5C77129; Fri, 27 Nov 2009 01:33:41 +0100 (CET)
X-Original-To: sc22wg5@open-std.org
Delivered-To: sc22wg5@open-std.org
Received: from ns.nag-j.co.jp (218-42-159-107.cust.bit-drive.ne.jp [218.42.159.107])
	by www2.open-std.org (Postfix) with ESMTP id CCD4FC77121
	for <sc22wg5@open-std.org>; Fri, 27 Nov 2009 01:33:38 +0100 (CET)
Received: from 218-42-159-108.cust.bit-drive.ne.jp ([218.42.159.108] helo=Marucomputer)
	by ns.nag-j.co.jp with smtp (Exim 4.50)
	id 1NDokS-00062C-7O
	for sc22wg5@open-std.org; Fri, 27 Nov 2009 09:31:44 +0900
Message-ID: <F50155AE514D437CA7AA0E3C6A0900B0@Marucomputer>
From: "Malcolm Cohen" <malcolm@nag-j.co.jp>
To: "WG5" <sc22wg5@open-std.org>
References: <4B0ECF95.1040209@lbl.gov> <20091126224156.4BCB9C76BCD@www2.open-std.org>
In-Reply-To: <20091126224156.4BCB9C76BCD@www2.open-std.org>
Subject: Re: [ukfortran] (SC22WG5.4129) (j3.2006) Interoperability of dummyarrays
Date: Fri, 27 Nov 2009 09:34:07 +0900
Organization: =?utf-8?B?5pel5pysTkFH?=
MIME-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="utf-8";
	reply-type=response
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Mailer: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Sender: owner-sc22wg5@open-std.org
Precedence: bulk

> 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.

Cheers,
-- 
................................Malcolm Cohen, Nihon NAG, Tokyo.
 

