ISO/IEC TS 29113:2012
(Main)Information technology - Further interoperability of Fortran with C
Information technology - Further interoperability of Fortran with C
ISO/IEC TS 29113:2012 specifies the form and establishes the interpretation of facilities that extend the Fortran language defined by ISO/IEC 15391:2010. The purpose of ISO/IEC TS 29113:2012 is to promote portability, reliability, maintainability and efficient execution of programs containing parts written in Fortran and parts written in C, for use on a variety of computing systems.
Technologies de l'information — Interopérabilité ultérieure de Fortran avec C
General Information
Frequently Asked Questions
ISO/IEC TS 29113:2012 is a technical specification published by the International Organization for Standardization (ISO). Its full title is "Information technology - Further interoperability of Fortran with C". This standard covers: ISO/IEC TS 29113:2012 specifies the form and establishes the interpretation of facilities that extend the Fortran language defined by ISO/IEC 15391:2010. The purpose of ISO/IEC TS 29113:2012 is to promote portability, reliability, maintainability and efficient execution of programs containing parts written in Fortran and parts written in C, for use on a variety of computing systems.
ISO/IEC TS 29113:2012 specifies the form and establishes the interpretation of facilities that extend the Fortran language defined by ISO/IEC 15391:2010. The purpose of ISO/IEC TS 29113:2012 is to promote portability, reliability, maintainability and efficient execution of programs containing parts written in Fortran and parts written in C, for use on a variety of computing systems.
ISO/IEC TS 29113:2012 is classified under the following ICS (International Classification for Standards) categories: 35.060 - Languages used in information technology. The ICS classification helps identify the subject area and facilitates finding related standards.
You can purchase ISO/IEC TS 29113:2012 directly from iTeh Standards. The document is available in PDF format and is delivered instantly after payment. Add the standard to your cart and complete the secure checkout process. iTeh Standards is an authorized distributor of ISO standards.
Standards Content (Sample)
TECHNICAL ISO/IEC
SPECIFICATION TS
First edition
2012-12-01
Information technology — Further
interoperability of Fortran with C
Technologies de l'information — Interopérabilité ultérieure de Fortran
avec C
Reference number
©
ISO/IEC 2012
© ISO/IEC 2012
All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized in any form or by any means,
electronic or mechanical, including photocopying and microfilm, without permission in writing from either ISO at the address below or
ISO's member body in the country of the requester.
ISO copyright office
Case postale 56 • CH-1211 Geneva 20
Tel. + 41 22 749 01 11
Fax + 41 22 749 09 47
E-mail copyright@iso.org
Web www.iso.org
Published in Switzerland
ii © ISO/IEC 2012 – All rights reserved
Contents
1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Normative references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Terms and denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4 Compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.1 New intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.2 Fortran 2008 compatibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5 Type speciers and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.1 Assumed-type objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.2 Assumed-rank objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
5.3 ALLOCATABLE, OPTIONAL, and POINTER attributes . . . . . . . . . . . . . . . . . . . . . . 10
5.4 ASYNCHRONOUS attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
5.4.2 Asynchronous communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6 Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.1 Characteristics of dummy data objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.2 Explicit interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.3 Argument association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.4 Intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.4.1 SHAPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.4.2 SIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6.4.3 UBOUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
7 New intrinsic procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
7.2 RANK (A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
8 Interoperability with C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8.1 Removed restrictions on ISO C BINDING module procedures . . . . . . . . . . . . . . . . . . . . 17
8.2 C descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8.3 ISO Fortran binding.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8.3.1 Summary of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
8.3.2 CFI dim t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
8.3.3 CFI cdesc t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
8.3.4 Macros and typedefs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8.3.5 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
8.4 Restrictions on C descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.5 Restrictions on formal parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
8.6 Restrictions on lifetimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
8.7 Interoperability of procedures and procedure interfaces . . . . . . . . . . . . . . . . . . . . . . . . 30
9 Required editorial changes to ISO/IEC 1539-1:2010(E) . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
9.1 General . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
9.2 Edits to Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
© ISO/IEC 2012 – All rights reserved
i
9.3 Edits to clause 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
9.4 Edits to clause 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.5 Edits to clause 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
9.6 Edits to clause 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
9.7 Edits to clause 12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.8 Edits to clause 13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
9.9 Edits to clause 15 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
9.10 Edits to clause 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
9.11 Edits to annex A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
9.12 Edits to annex C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Annex A (informative) Extended notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
A.1 Clause 5 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
A.1.1 Using assumed type in the context of interoperation with C . . . . . . . . . . . . . . . . 43
A.1.2 Mapping of interfaces with void * C parameters to Fortran . . . . . . . . . . . . . . . . . 43
A.1.3 Using assumed-type variables in Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
A.1.4 Simplifying interfaces for arbitrary rank procedures . . . . . . . . . . . . . . . . . . . . . 46
A.2 Clause 8 notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
A.2.1 Dummy arguments of any type and rank . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
A.2.2 Creating a contiguous copy of an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
A.2.3 Changing the attributes of an array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
A.2.4 Creating an array section in C using CFI section . . . . . . . . . . . . . . . . . . . . . . 50
A.2.5 Use of CFI setpointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
A.2.6 Mapping of MPI interfaces to Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
© ISO/IEC 2012 – All rights reserved
ii
List of Tables
8.1 Macros specifying attribute codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8.2 Macros specifying type codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
8.3 Macros specifying error codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
© ISO/IEC 2012 – All rights reserved
iii
Foreword
ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commis-
sion) form the specialized system for worldwide standardization. National bodies that are members of ISO or
IEC participate in the development of International Standards through technical committees established by the
respective organization to deal with particular elds of technical activity. ISO and IEC technical committees
collaborate in elds of mutual interest. Other international organizations, governmental and nongovernmental,
in liaison with ISO and IEC, also take part in the work. In the eld of information technology, ISO and IEC have
established a joint technical committee, ISO/IEC JTC 1.
International Standards are drafted in accordance with the rules given in the ISO/IEC Directives, Part 2.
The main task of the joint technical committee is to prepare International Standards. Draft International Stand-
ards adopted by the joint technical committee are circulated to national bodies for voting. Publication as an
International Standard requires approval by at least 75 % of the national bodies casting a vote.
In other circumstances, particularly when there is an urgent market requirement for such documents, the joint
technical committee may decide to publish an ISO/IEC Technical Specication (ISO/IEC TS), which represents
an agreement between the members of the joint technical committee and is accepted for publication if it is
approved by 2/3 of the members of the committee casting a vote.
An ISO/IEC TS is reviewed after three years in order to decide whether it will be conrmed for a further three
years, revised to become an International Standard, or withdrawn. If the ISO/IEC TS is conrmed, it is reviewed
again after a further three years, at which time it must either be transformed into an International Standard or
be withdrawn.
Attention is drawn to the possibility that some of the elements of this document may be the subject of patent
rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights.
Subcommittee SC22, Programming languages, their environments and system software interfaces.
© ISO/IEC 2012 – All rights reserved
iv
Introduction
The system for interoperability between the C language, as standardized by ISO/IEC 9899:1999, and Fortran, as
standardized by ISO/IEC 1539-1:2010, provides for interoperability of procedure interfaces with arguments that
are non-optional scalars, explicit-shape arrays, or assumed-size arrays. These are the cases where the Fortran
and C data concepts directly correspond. Interoperability is not provided for important cases where there is not
a direct correspondence between C and Fortran.
The existing system for interoperability does not provide for interoperability of interfaces with Fortran dummy ar-
guments that are assumed-shape arrays, have assumed character length, or have the ALLOCATABLE, POINTER,
or OPTIONAL attributes. As a consequence, a signicant class of Fortran subprograms is not portably accessible
from C, limiting the usefulness of the facility.
The provision in the existing system for interoperability with a C formal parameter that is a pointer to void is
inconvenient to use and error-prone. C functions with such parameters are widely used.
This Technical Specication extends the facility of Fortran for interoperating with C to provide for interoperability
of procedure interfaces that specify dummy arguments that are assumed-shape arrays, have assumed character
length, or have the ALLOCATABLE, POINTER, or OPTIONAL attributes. New Fortran concepts of assumed
type and assumed rank are introduced. The former simplies interoperation with formal parameters of type
(void *). The latter facilitates interoperability with C functions that can accept arguments of arbitrary rank. An
intrinsic function, RANK, is specied to obtain the rank of an assumed-rank variable.
The facility specied in this Technical Specication is a compatible extension of Fortran as standardized by
ISO/IEC 1539-1:2010. It does not require that any changes be made to the C language as standardized by
ISO/IEC 9899:1999.
It is the intention of ISO/IEC JTC 1/SC22 that the semantics and syntax specied by this Technical Specication
be included in the next revision of ISO/IEC 1539-1 without change unless experience in the implementation
and use of this feature identies errors that need to be corrected, or changes are needed to achieve proper
integration, in which case every reasonable eort will be made to minimize the impact of such changes on existing
implementations.
This Technical Specication is organized in 9 clauses:
Scope Clause 1
Normative references Clause 2
Terms and denitions Clause 3
Compatibility Clause 4
Type speciers and attributes Clause 5
Procedures Clause 6
New intrinsic procedure Clause 7
Interoperability with C Clause 8
Required editorial changes to ISO/IEC 1539-1:2010(E) Clause 9
It also contains the following nonnormative material:
Extended notes Annex A
NOTE 0.1
ISO/IEC 1539-1:2010 references ISO/IEC 9899:1999. For consistency, this Technical Specication also
references ISO/IEC 9899:1999, not ISO/IEC 9899:2011.
© ISO/IEC 2012 – All rights reserved
v
TECHNICAL SPECIFICATION ISO/IEC TS 29113:2012(E)
Information technology — Further interoperability of Fortran
with C
1 Scope
This Technical Specication species the form and establishes the interpretation of facilities that extend the
Fortran language dened by ISO/IEC 1539-1:2010. The purpose of this Technical Specication is to promote
portability, reliability, maintainability, and ecient execution of programs containing parts written in Fortran
and parts written in C, for use on a variety of computing systems.
© ISO/IEC 2012 – All rights reserved
(Blank page)
© ISO/IEC 2012 – All rights reserved
2 Normative references
The following referenced standards are indispensable for the application of this document. For dated references,
only the edition cited applies. For undated references, the latest edition of the referenced document (including
any amendments) applies.
ISO/IEC 1539-1:2010, Information technology|Programming languages|Fortran|Part 1:Base language
ISO/IEC 9899:1999, Programming languages|C
© ISO/IEC 2012 – All rights reserved
(Blank page)
© ISO/IEC 2012 – All rights reserved
3 Terms and denitions
For the purposes of this document, the terms and denitions given in ISO/IEC 1539-1:2010 and the following
apply.
3.1
assumed-rank object
dummy variable whose rank is assumed from its eective argument
3.2
assumed-type object
dummy variable declared with the TYPE(*) type specier
3.3
C descriptor
C structure of type CFI cdesc t
NOTE 3.1
A C descriptor is used to describe a Fortran object that has no exact analog in C.
© ISO/IEC 2012 – All rights reserved
(Blank page)
© ISO/IEC 2012 – All rights reserved
4 Compatibility
4.1 New intrinsic procedures
This Technical Specication denes an intrinsic procedure in addition to those specied in ISO/IEC 1539-1:2010.
Therefore, a Fortran program conforming to ISO/IEC 1539-1:2010 might have a dierent interpretation under this
Technical Specication if it invokes an external procedure having the same name as the new intrinsic procedure,
unless that procedure is specied to have the EXTERNAL attribute.
4.2 Fortran 2008 compatibility
This Technical Specication species an upwardly compatible extension to ISO/IEC 1539-1:2010.
© ISO/IEC 2012 – All rights reserved
(Blank page)
© ISO/IEC 2012 – All rights reserved
5 Type speciers and attributes
5.1 Assumed-type objects
The syntax rule R403 declaration-type-spec in subclause 4.3.1.1 of ISO/IEC 1539-1:2010 is replaced by
R403 declaration-type-spec is intrinsic-type-spec
or TYPE ( intrinsic-type-spec )
or TYPE ( derived-type-spec )
or CLASS ( derived-type-spec )
or CLASS ( * )
or TYPE ( * )
An entity declared with a declaration-type-spec of TYPE (*) is an assumed-type entity. It has no declared type
and its dynamic type and type parameters are assumed from its eective argument. An assumed-type object is
unlimited polymorphic.
C407a An assumed-type entity shall be a dummy variable that does not have the ALLOCATABLE, CODIMEN-
SION, INTENT(OUT), POINTER, or VALUE attribute and is not an explicit-shape array.
C407b An assumed-type variable name shall not appear in a designator or expression except as an actual
argument corresponding to a dummy argument that is assumed-type, or as the rst argument to any of
the intrinsic and intrinsic module functions IS CONTIGUOUS, LBOUND, PRESENT, RANK, SHAPE,
SIZE, UBOUND, and C LOC.
C407c An assumed-type actual argument that corresponds to an assumed-rank dummy argument shall be
assumed-shape or assumed-rank.
NOTE 5.1
An assumed-type object that is not assumed-shape and not assumed-rank is intended to be passed as the
C address of the object. This means that there would be insucient information passed for an assumed-
type explicit-shape array that is an actual argument corresponding to an assumed-shape dummy argument.
Therefore TYPE(*) explicit-shape is not permitted.
NOTE 5.2
This Technical Specication provides no mechanism for a Fortran procedure to determine the actual type
of an assumed-type argument.
5.2 Assumed-rank objects
The syntax rule R515 array-spec in subclause 5.3.8.1 of ISO/IEC 1539-1:2010 is replaced by
R515 array-spec is explicit-shape-spec-list
or assumed-shape-spec-list
or deferred-shape-spec-list
or assumed-size-spec
or implied-shape-spec-list
or assumed-rank-spec
An assumed-rank object is a dummy variable whose rank is assumed from its eective argument. An assumed-rank
object is declared with an array-spec that is an assumed-rank-spec.
© ISO/IEC 2012 – All rights reserved
R522a assumed-rank-spec is .
C535a An assumed-rank entity shall be a dummy variable that does not have the CODIMENSION or VALUE
attribute.
An assumed-rank object may have the CONTIGUOUS attribute.
C535b An assumed-rank variable name shall not appear in a designator or expression except as an actual
argument corresponding to a dummy argument that is assumed-rank, the argument of the C LOC function
in the ISO C BINDING intrinsic module, or the rst argument in a reference to an intrinsic inquiry
function.
C535c If an assumed-size or nonallocatable nonpointer assumed-rank array is an actual argument corresponding
to a dummy argument that is an INTENT(OUT) assumed-rank array, it shall not be polymorphic,
nalizable, of a type with an allocatable ultimate component, or of a type for which default initialization
is specied.
The denition of TKR compatible in paragraph 2 of subclause 12.4.3.4.5 of ISO/IEC 1539-1:2010 is changed to:
A dummy argument is type, kind, and rank compatible, or TKR compatible, with another dummy
argument if the rst is type compatible with the second, the kind type parameters of the rst have
the same values as the corresponding kind type parameters of the second, and both have the same
rank or either is assumed-rank.
NOTE 5.3
The intrinsic inquiry function RANK can be used to inquire about the rank of a data object. The rank of
an assumed-rank object is zero if the rank of the corresponding actual argument is zero.
NOTE 5.4
Assumed rank is an attribute of a Fortran dummy argument. When a C function is invoked with an
actual argument that corresponds to an assumed-rank dummy argument in a Fortran interface for that C
function, the corresponding formal parameter is the address of a descriptor of type CFI cdesc t (8.7). The
rank member of the descriptor provides the rank of the actual argument. The C function should therefore
be able to handle any rank. On each invocation, the rank is available to it.
5.3 ALLOCATABLE, OPTIONAL, and POINTER attributes
The ALLOCATABLE, OPTIONAL, and POINTER attributes may be specied for a dummy argument in a
procedure interface that has the BIND attribute.
The constraint C1255 in subclause 12.6.2.2 of ISO/IEC 1539-1:2010 is replaced by the following three constraints.
C1255 (R1230) If proc-language-binding-spec is specied for a procedure, each dummy argument shall be an in-
teroperable procedure (15.3.7) or a variable that is interoperable (15.3.5, 15.3.6), assumed shape, assumed
rank, assumed type, of assumed character length, or has the ALLOCATABLE or POINTER attribute. If
proc-language-binding-spec is specied for a function, the function result shall be an interoperable scalar
variable.
C1255a (R1230) A dummy argument of a procedure that has a proc-language-binding-spec shall not have both
the OPTIONAL and VALUE attributes.
C1255b (R1230) A variable that is a dummy argument of a procedure that has a proc-language-binding-spec shall
be of interoperable type or assumed type.
© ISO/IEC 2012 – All rights reserved
The following constraint is added to subclause 5.3.6.1 of ISO/IEC 1539-1:2010.
C524a A coarray shall not be a dummy argument of a procedure that has a proc-language-binding-spec.
Constraint C516 in subclause 5.3.1 of ISO/IEC 1539-1:2010 says \The ALLOCATABLE, POINTER, or OP-
TIONAL attribute shall not be specied for a dummy argument of a procedure that has a proc-language-binding-
spec." This is replaced by the following, less restrictive constraint.
C516 The ALLOCATABLE or POINTER attribute shall not be specied for a default-initialized dummy
argument of a procedure that has a proc-language-binding-spec.
NOTE 5.5
It would be a severe burden to implementors to require that CFI allocate initialize components of an object
of a derived type with default initialization. The alternative of not requiring initialization would have been
inconsistent with the eect of ALLOCATE in Fortran.
5.4 ASYNCHRONOUS attribute
5.4.1 Introduction
The ASYNCHRONOUS attribute is extended to apply to variables that are used for asynchronous communication.
5.4.2 Asynchronous communication
Asynchronous communication for a Fortran variable occurs through the action of procedures dened by means
other than Fortran. It is initiated by execution of an asynchronous communication initiation procedure and
completed by execution of an asynchronous communication completion procedure. Between the execution of the
initiation and completion procedures, any variable of which any part is associated with any part of the asyn-
chronous communication variable is a pending communication aector. Whether a procedure is an asynchronous
communication initiation or completion procedure is processor dependent.
Asynchronous communication is either input communication or output communication. For input communication,
a pending communication aector shall not be referenced, become dened, become undened, become associated
with a dummy argument that has the VALUE attribute, or have its pointer association status changed. For
output communication, a pending communication aector shall not be redened, become undened, or have its
pointer association status changed.
NOTE 5.6
Asynchronous communication can be used for nonblocking MPI calls such as MPI IRECV and MPI ISEND.
For example,
REAL :: BUF(100,100)
... ! Code that involves BUF
BLOCK
ASYNCHRONOUS :: BUF
CALL MPI_IRECV(BUF,.REQ,.)
... ! Code that does not involve BUF
CALL MPI_WAIT(REQ,.)
END BLOCK
... ! Code that involves BUF
In this example, there is asynchronous input communication and BUF is a pending communication aector
between the two calls. MPI IRECV may return while the communication (reading values into BUF) is still
underway. The intent is that the code between MPI IRECV and MPI WAIT executes without waiting for
this communication to complete. The restrictions are the same as for asynchronous input data transfer.
© ISO/IEC 2012 – All rights reserved
NOTE 5.6 (cont.)
Similar code with the call of MPI IRECV replaced by a call of MPI ISEND is asynchronous output com-
munication. The restrictions are the same as for asynchronous output data transfer.
© ISO/IEC 2012 – All rights reserved
6 Procedures
6.1 Characteristics of dummy data objects
Additionally to the characteristics listed in subclause 12.3.2.2 of ISO/IEC 1539-1:2010, whether the type or rank
of a dummy data object is assumed is a characteristic of the dummy data object.
6.2 Explicit interface
Additionally to the rules of subclause 12.4.2.2 of ISO/IEC 1539-1:2010, a procedure shall have an explicit interface
if it has a dummy argument that is assumed-rank.
NOTE 6.1
An explicit interface is also required for a procedure if it has a dummy argument that is assumed-type
because an assumed-type dummy argument is polymorphic.
6.3 Argument association
An assumed-rank dummy argument may correspond to an actual argument of any rank. If the actual argument
has rank zero, the dummy argument has rank zero; the shape is a zero-sized array and the LBOUND and
UBOUND intrinsic functions, with no DIM argument, return zero-sized arrays. If the actual argument has rank
greater than zero, the rank and extents of the dummy argument are assumed from the actual argument, including
the lack of a nal extent in the case of an assumed-size array. If the actual argument is an array and the dummy
argument is allocatable or a pointer, the bounds of the dummy argument are assumed from the actual argument.
An assumed-type dummy argument shall not correspond to an actual argument that is of a derived type that has
type parameters, type-bound procedures, or nal subroutines.
When a Fortran procedure that has an INTENT(OUT) allocatable dummy argument is invoked by a C function,
and the actual argument in the C function is the address of a C descriptor that describes an allocated allocatable
variable, the variable is deallocated on entry to the Fortran procedure.
When a C function is invoked from a Fortran procedure via an interface with an INTENT(OUT) allocatable
dummy argument, and the actual argument in the reference to the C function is an allocated allocatable variable,
the variable is deallocated on invocation (before execution of the C function begins).
6.4 Intrinsic procedures
6.4.1 SHAPE
The description of the intrinsic function SHAPE in ISO/IEC 1539-1:2010 is changed for an assumed-rank array
that is associated with an assumed-size array; an assumed-size array has no shape, but in this case the result has
a value equal to [ (SIZE (ARRAY, I, KIND), I=1, RANK (ARRAY)) ] with KIND omitted from SIZE if it was
omitted from SHAPE.
6.4.2 SIZE
The description of the intrinsic function SIZE in ISO/IEC 1539-1:2010 is changed in the following cases:
© ISO/IEC 2012 – All rights reserved
(1) for an assumed-rank object that is associated with an assumed-size array, the result has the value1
if DIM is present and equal to the rank of ARRAY, and a negative value that is equal to PRODUCT
( [ (SIZE (ARRAY, I, KIND), I=1, RANK (ARRAY)) ] ) if DIM is not present;
(2) for an assumed-rank object that is associated with a scalar, the result has the value 1.
6.4.3 UBOUND
The description of the intrinsic function UBOUND in ISO/IEC 1539-1:2010 is changed for an assumed-rank
object that is associated with an assumed-size array; the result of UBOUND (ARRAY, RANK(ARRAY), KIND)
has a value equal to LBOUND (ARRAY, RANK (ARRAY), KIND)2 with KIND omitted from LBOUND if it
was omitted from UBOUND.
NOTE 6.2
If LBOUND or UBOUND is invoked for an assumed-rank object that is associated with a scalar and DIM
is absent, the result is a zero-sized array. LBOUND or UBOUND cannot be invoked for an assumed-rank
object that is associated with a scalar if DIM is present because the rank of a scalar is zero and DIM must
be 1.
© ISO/IEC 2012 – All rights reserved
7 New intrinsic procedure
7.1 General
Detailed specication of the generic intrinsic function RANK is provided in 7.2. The types and type parameters of
the RANK intrinsic procedure argument and function result are determined by this specication. The \Argument"
paragraph species requirements on the actual arguments of the procedure. The intrinsic function RANK is pure.
7.2 RANK (A)
Description. Rank of a data object.
Class. Inquiry function.
Argument.
A shall be a scalar or array of any type.
Result Characteristics. Default integer scalar.
Result Value. The result is the rank of A.
Example. If X is a dummy argument declared with REAL X(.) and is argument associated with an actual
argument that was declared REAL Y(:,:,:), RANK(X) has the value 3.
© ISO/IEC 2012 – All rights reserved
(Blank page)
© ISO/IEC 2012 – All rights reserved
8 Interoperability with C
8.1 Removed restrictions on ISO C BINDING module procedures
The subroutine C F POINTER from the intrinsic module ISO C BINDING has the restriction in ISO/IEC 1539-
1:2010 that if FPTR is an array, it shall be of interoperable type.
The function C F PROCPOINTER from the intrinsic module ISO C BINDING has the restriction in ISO/IEC
1539-1:2010 that CPTR and FPTR shall not be the C address and interface of a noninteroperable Fortran
procedure.
The function C LOC from the intrinsic module ISO C BINDING has the restriction in ISO/IEC 1539-1:2010 that
if X is an array, it shall be of interoperable type.
The function C FUNLOC from the intrinsic module ISO C BINDING has the restriction in ISO/IEC 1539-1:2010
that its argument shall be interoperable.
These restrictions are removed.
If the value of a C function pointer will be the result of a reference to C FUNLOC with a noninteroperable
argument, it is recommended that the C function pointer be declared void(*)().
8.2 C descriptors
A C descriptor is a C structure of type CFI cdesc t. Together with library functions that have standard prototypes,
it provides a means for describing and manipulating Fortran data objects from within a C function. This C
structure is dened in the le ISO_Fortran_binding.h.
8.3 ISO Fortran binding.h
8.3.1 Summary of contents
The ISO_Fortran_binding.h header le shall contain the denitions of the C structures CFI cdesc t and CFI -
dim t, typedef denitions for CFI attribute t, CFI index t, CFI rank t, and CFI type t, the denition of the
macro CFI CDESC T, macro denitions that expand to integer constants, and C function prototypes or macro
denitions for CFI address, CFI allocate, CFI deallocate, CFI establish, CFI is contiguous, CFI section, CFI -
select part, and CFI setpointer. The types, macros, and functions declared in ISO_Fortran_binding.h can be
used by a C function to interpret a C descriptor and allocate and deallocate objects represented by a C descriptor.
These provide a means to specify a C prototype that interoperates with a Fortran interface that has an allocatable,
assumed character length, assumed-rank, assumed-shape, or data pointer dummy argument.
ISO_Fortran_binding.h may be included in any order relative to the standard C headers, and may be included
more than once in a given scope, with no eect dierent from being included only once, other than the eect on
line numbers.
A C source le that includes the ISO_Fortran_binding.h header le shall not use any names starting with
CFI that are not dened in the header, and shall not dene any of the structure names dened in the header
as macro names. All names other than structure member names dened in the header begin with CFI or an
underscore character, or are dened by a standard C header that it includes.
© ISO/IEC 2012 – All rights reserved
8.3.2 CFI dim t
CFI dim t is a named C structure type dened by a typedef. It is used to represent lower bound, extent, and
memory stride information for one dimension of an array. The type CFI index t is described in 8.3.4. CFI dim t
contains at least the following members in any order.
CFI index t lower bound; The value is equal to the value of the lower bound for the dimension being de-
scribed.
CFI index t extent; The value is equal to the number of elements along the dimension being described, or the
value -1 for the nal dimension of an assumed-size array.
CFI index t sm; The value is equal to the memory stride for a dimension. The value is the distance in bytes
between the beginnings of successive elements along the dimension being described.
8.3.3 CFI cdesc t
CFI cdesc t is a named C structure type dened by a typedef, containing a
exible array member. It shall contain
at least the members described in the list that follows this paragraph. The values of these members of a structure
of type CFI cdesc t that is produced by the functions and macros specied in this Technical Specication, or
received by a C function when invoked by a Fortran procedure, shall have the following properties. The rst three
members of the structure shall be base_addr, elem_len, and version in that order. The nal member shall be
dim, with the other members after version and before dim in any order. The types CFI attribute t, CFI rank t,
and CFI type t are described in 8.3.4. The type CFI dim t is described in 8.3.2.
void * base addr; If the object is an unallocated allocatable variable or a pointer that is disassociated, the
value is a null pointer. If the object has zero size, the value is not a null pointer but is otherwise processor-
dependent. Otherwise, the value is the base address of the object being described. The base address of a
scalar is its C address. The base address of an array is the C address of the rst element in Fortran array
element order (6.5.3.2 of ISO/IEC 1539-1:2010).
size t elem len; If the object is scalar, the value is the storage size in bytes of the object; otherwise, the value
is the storage size in bytes of an element of the object.
int version; The value is equal to the value of CFI VERSION in the ISO_Fortran_binding.h header le that
dened the format and meaning of this C descriptor when the descriptor was established.
CFI rank t rank; The value is equal to the number of dimensions of the Fortran object being described. If the
object is a scalar, the value is zero.
CFI type t type; The value is equal to the specier for the type of the object. Each interoperable intrinsic C
type has a specier. Speciers are also provided to indicate that the type of the object is an interoperable
structure, or is unknown. The macros listed in Table 8.2 provide values that correspond to each specier.
CFI attribute t attribute; The value is equal to the value of an attribute code that indicates whether the
object described is allocatable, a data pointer, or a nonallocatable nonpointer data object. The macros
listed in Table 8.1 provide values that correspond to each code.
CFI dim t dim[ ]; The number of elements in the dim array is equal to the rank of the object. Each element of
the array contains the lower bound, extent, and memory stride information for the corresponding dimension
of the Fortran object.
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.
© ISO/IEC 2012 – All rights reserved
There shall be an ordering of the dimensions such that the absolute value of the sm member of the rst dimension
is not less than the elem_len member of the C descriptor and the absolute value of the sm member of each
subsequent dimension is not less than the absolute value of the sm member of the previous dimension multiplied
by the extent of the previous dimension.
In a C descriptor of an assumed-size array, the extent member of the last element of the dim member has the
value1.
NOTE 8.1
The reason for the restriction on the absolute values of the sm members is to ensure that there is no overlap
between the elements of the array that is being described, while allowing for the reordering of subscripts.
Within Fortran, such a reordering can be achieved with the intrinsic function TRANSPOSE or the intrinsic
function RESHAPE with the optional argument ORDER, and an optimizing compiler can accommodate it
without making a copy by constructing the appropriate descriptor whenever it can determine that a copy
is not needed.
NOTE 8.2
The value ofelem_len for a Fortran CHARACTER object is equal to the character length times the number
of bytes of a single character of that kind. If the kind is C CHAR, this value will be equal to the character
length.
8.3.4 Macros and typedefs
The macros and typedefs described in this subclause are dened in ISO_Fortran_binding.h. Except for CFI -
CDESC T, each macro expands to an integer constant expression that is either a single token or a parenthesized
expression that is suitable for use in #if preprocessing directives.
CFI CDESC T is a function-like macro that takes one argument, which is the rank of the C descriptor to create,
and evaluates to an unqualied type of suitable size and alignment for dening a variable to use as a C descriptor
of that rank. The argument shall be an integer constant expression with a value that is greater than or equal to
zero and less than or equal to CFI MAX RANK. A pointer to a variable declared using CFI CDESC T can be
cast to CFI cdesc t *. A variable declared using CFI CDESC T shall not have an initializer.
NOTE 8.3
The CFI CDESC T macro provides the memory for a C descriptor. The address of an entity declared using
the macro is not usable as an actual argument corresponding to a formal parameter of type CFI cdesc t *
without an explicit cast. For example, the following code uses CFI CDESC T to declare a C descriptor of
rank 5 and pass it to CFI deallocate (8.3.5.4).
CFI_CDESC_T(5) object;
int ind;
... code to define and use C descriptor ...
ind = CFI_deallocate((CFI_cdesc_t *) &object);
CFI index t is a typedef name for a standard signed integer type capable of representing the result of subtracting
two pointers.
The CFI MAX RANK macro has a processor-dependent value equal to the largest rank supported. The value
shall be greater than or equal to 15. CFI rank t is a typedef name for a standard integer type capable of
representing the largest supported rank.
The CFI VERSION macro has a processor-dependent value that encodes the version of the ISO_Fortran_-
binding.h header le containing this macro.
© ISO/IEC 2012 – All rights reserved
NOTE 8.4
The intent is that the version should be increased every time that the header is incompatibly changed, and
that the version in a C descriptor may be used to provide a level of upwards compatibility, by using means
not dened by this Technical Specication.
The macros in Table 8.1 are for use as attribute codes. The values shall be nonnegative and distinct. CFI -
attribute t is a typedef name for a standard integer type capable of representing the values of the attribute
codes.
Table 8.1: Macros specifying attribute codes
Macro Code
CFI attribute pointer data pointer
CFI attribute allocatable allocatable
CFI attribute other nonallocatable nonpointer
CFI attribute pointer species a data object with the Fortran POINTER attribute. CFI attribute allocatable
species an object with the Fortran ALLOCATABLE attribute. CFI attribute other species a nonallocatable
nonpointer object.
The macros in Table 8.2 are for use as type speciers. The value for CFI type other shall be negative and distinct
from all other type speciers. CFI type struct species a C structure that is interoperable with a Fortran derived
type; its value shall be positive and distinct from all other type speciers. If a C type is not interoperable
with a Fortran type and kind supported by the Fortran processor, its macro shall evaluate to a negative value.
Otherwise, the value for an intrinsic type shall be positive.
Additional nonnegative processor-dependent type specier values may be dened for Fortran intrinsic types
that are not represented by other type speciers and noninteroperable Fortran derived types that do not have
type parameters, type-bound procedures, nal subroutines, nor components that have the ALLOCATABLE or
POINTER attributes, or correspond to CFI type other.
CFI type t is a typedef name for a standard integer type capable of representing the values for the supported
type speciers.
Table 8.2: Macros specifying type codes
Macro C Type
CFI type signed char signed char
CFI type short short int
CFI type int int
CFI type long long int
CFI type long long long long int
CFI type size t size t
CFI type int8 t int8 t
CFI type int16 t int16 t
CFI type int32 t int32 t
CFI type int64 t int64 t
CFI type int least8 t int least8 t
CFI type int least16 t int least16 t
CFI type int least32 t int least32 t
CFI type int least64 t int least64 t
CFI type int fast8 t int fast8 t
CFI type int fast16 t int fast16 t
CFI type int fast32 t int fast32 t
CFI type int fast64 t int fast64 t
© ISO/IEC 2012 – All rights reserved
Macros specifying type codes (cont.)
Macro C Type
CFI type intmax t intmax t
CFI type intptr t intptr t
CFI type ptrdi t ptrdi t
CFI type
oat
oat
CFI type double double
CFI type long double long double
CFI type
oat Complex
oat Complex
CFI type double Complex double Complex
CFI type long double Complex long double Complex
CFI type Bool Bool
CFI type char char
CFI type cptr void *
CFI type struct interoperable C structure
CFI type other Not otherwise specied
NOTE 8.5
The speciers for two intrinsic types can have the same value. For example, CFI type int and CFI type -
int32 t might have the same value.
The macros in Table 8.3 are for use as error codes. The macro CFI SUCCESS shall be dened to be the integer
constant 0. The value of each macro other than CFI SUCCESS shall be nonzero and shall be dierent from the
values of the other macros specied in this subclause. Error conditions other than those listed in this subclause
should be indicated by error codes dierent from the values of the macros named in this subclause.
The error codes that indicate the following error conditions are named by the associated macro name.
Table 8.3: Macros specifying error codes
Macro Error
CFI SUCCESS No error detected.
CFI ERROR BASE ADDR NULL The base address member of a C descriptor is a null pointer
in a context that requires a non-null pointer value.
CFI ERROR BASE ADDR NOT NULL The base address member of a C descriptor is not a nu
...








Questions, Comments and Discussion
Ask us and Technical Secretary will try to provide an answer. You can facilitate discussion about the standard in here.
Loading comments...