From owner-sc22wg5@open-std.org  Tue Dec  9 13:24:38 2008
Return-Path: <owner-sc22wg5@open-std.org>
X-Original-To: sc22wg5-dom7
Delivered-To: sc22wg5-dom7@www2.open-std.org
Received: by www2.open-std.org (Postfix, from userid 521)
	id 8F318CA343D; Tue,  9 Dec 2008 13:24:38 +0100 (CET)
X-Original-To: sc22wg5@open-std.org
Delivered-To: sc22wg5@open-std.org
Received: from ppsw-6.csi.cam.ac.uk (ppsw-6.csi.cam.ac.uk [131.111.8.136])
	by www2.open-std.org (Postfix) with ESMTP id 0A3CACA3439
	for <sc22wg5@open-std.org>; Tue,  9 Dec 2008 13:24:37 +0100 (CET)
X-Cam-AntiVirus: no malware found
X-Cam-SpamDetails: not scanned
X-Cam-ScannerInfo: http://www.cam.ac.uk/cs/email/scanner/
Received: from hermes-1.csi.cam.ac.uk ([131.111.8.51]:52653)
	by ppsw-6.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.156]:25)
	with esmtpa (EXTERNAL:nmm1) id 1LA1dl-0001pt-K0 (Exim 4.70) for sc22wg5@open-std.org
	(return-path <nmm1@hermes.cam.ac.uk>); Tue, 09 Dec 2008 12:24:37 +0000
Received: from prayer by hermes-1.csi.cam.ac.uk (hermes.cam.ac.uk)
	with local (PRAYER:nmm1) id 1LA1dl-0007kW-5y (Exim 4.67) for sc22wg5@open-std.org
	(return-path <nmm1@hermes.cam.ac.uk>); Tue, 09 Dec 2008 12:24:37 +0000
Received: from [131.111.10.32] by webmail.hermes.cam.ac.uk
	with HTTP (Prayer-1.3.1); 09 Dec 2008 12:24:37 +0000
Date: 09 Dec 2008 12:24:37 +0000
From: "N.M. Maclaren" <nmm1@cam.ac.uk>
To: WG5 <sc22wg5@open-std.org>
Subject: N1761, TYPE(*), BIND(C) and arrays
Message-ID: <Prayer.1.3.1.0812091224370.19674@hermes-1.csi.cam.ac.uk>
In-Reply-To: <20081202130345.82E16C178E1@www2.open-std.org>
References: <20081127193527.EF00DC178D9@www2.open-std.org>
 <20081202130345.82E16C178E1@www2.open-std.org>
X-Mailer: Prayer v1.3.1
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; charset=ISO-8859-1
Sender: owner-sc22wg5@open-std.org
Precedence: bulk

This is something that I subconsciously realised when reading N1761,
but only formulated what it was fairly recently.  Fortran does not have
the concept of a called procedure knowing anything about the properties
of its actual arguments (i.e. the objects and expressions in the calling
procedure).  The SOLE information available to a called procedure about
its arguments are in its OWN declaration (i.e. the properties of its
dummy arguments).

It overlaps with Reinhold's points to a considerable extent, of course.

That makes TYPE(*) effectively non-interoperable with the proposal to
have two incompatible argument passing mechanisms for BIND(C), which
are selected solely on the types of argument.

Here is an example program.  Yes, some of the examples may already be
forbidden - I don't have time to check - and there may be other bugs.
But, for N1761 to be acceptable as a TR, all of these cases have to be
specified or stated to be processor dependent.  And please remember that
the TARGET and POINTER attributes have 'interesting' properties as far
as when aliasing and update are allowed.


MODULE Mudpuddle
    INTERFACE
        SUBROUTINE Slough (arg) BIND(C)
            TYPE(*), DIMENSION(..) :: arg
        END SUBROUTINE Slough
    END INTERFACE
END MODULE Mudpuddle

MODULE Morass
    REAL :: array_A(10) = 0.0
END MODULE Morass

PROGRAM Swamp
    USE Mudpuddle
    USE Morass
    REAL :: array_B(10) = 0.0
    REAL, ALLOCATABLE :: array_C(:)
    REAL, POINTER :: array_D(:)
    REAL, TARGET :: array_E(10) = 0.0
    INTEGER, PARAMETER :: index_P(10) = (/ (n, n = 1,10) /), &
        index_Q(3) = (/ 3, 4, 5, 6, 7 /), index_R = (/ 3, 5, 7 /)
    ALLOCATE(array_C(10))
    array_D => array_E

! For each of the following calls, is the array passed using descriptors
! or not, why, and where is that stated?  Note that many of those calls
! use expressions that just happen to deliver a contiguous section, and
! so an optimising compiler could use either mechanism.

    CALL Slough(array_A)
    CALL Slough(array_A(:))
    CALL Slough(array_A(3:7))
    CALL Slough(array_A(3:7:2))
    CALL Slough(array_A(index_P))
    CALL Slough(array_A(index_Q))
    CALL Slough(array_A(index_R))

    CALL Slough(array_B)
    CALL Slough(array_B(:))
    CALL Slough(array_B(3:7))
    CALL Slough(array_B(3:7:2))
    CALL Slough(array_B(index_P))
    CALL Slough(array_B(index_Q))
    CALL Slough(array_B(index_R))
 
    CALL Slough(array_C)
    CALL Slough(array_C(:))
    CALL Slough(array_C(3:7))
    CALL Slough(array_C(3:7:2))
    CALL Slough(array_C(index_P))
    CALL Slough(array_C(index_Q))
    CALL Slough(array_C(index_R))
 
    CALL Slough(array_D)
    CALL Slough(array_D(:))
    CALL Slough(array_D(3:7))
    CALL Slough(array_D(3:7:2))
    CALL Slough(array_D(index_P))
    CALL Slough(array_D(index_Q))
    CALL Slough(array_D(index_R))

    CALL Slough(array_E)
    CALL Slough(array_E(:))
    CALL Slough(array_E(3:7))
    CALL Slough(array_E(3:7:2))
    CALL Slough(array_E(index_P))
    CALL Slough(array_E(index_Q))
    CALL Slough(array_E(index_R))
END PROGRAM Swamp


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1@cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679


