(j3.2006) (SC22WG5.3787) N1761, TYPE(*), BIND(C) and arrays
N.M. Maclaren
nmm1 at cam.ac.uk
Tue Dec 9 07:24:37 EST 2008
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 at cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
More information about the J3
mailing list