J3/99-205 Date: 1999/06/09 To: J3 From: Matthijs van Waveren Subject: Edits for the sharing of global data between Fortran and C References: J3/98-165r1, J3/98-195r1, J3/98-196r2, J3/98-239 A. Introduction Paper J3/98-239 describes the approved syntax for interoperability between Fortran and C. The section before last in this paper describes the syntax for the sharing of global data between Fortran and C. The last section describes the syntax for the mapping of Fortran variable and procedure names to C variable and function names, which is informally known as "name mangling". Edits for these two sections still need to be written. This paper lists the edits for one of these sections, viz. the edits required to add the approved syntax for the sharing of global data between Fortran and C into the draft standard. There is some coupling between the syntax of global data and name mangling. Thus some of the edits are valid for both of these syntaxes. This is mentioned in the description of the individual edits. B. Edits Edits refer to J3/99-007R2 1. [10:36] Add to R214 or bind-stmt Edit number 2 refers to both global data and name mangling syntax. 2. [69:40] Add to R504 or BIND( C [, NAME = scalar-char-initialization-expr] [, BINDNAME = scalar-char-initialization-expr] ) 3. [70:9-11] Delete J3 note 147 4. [71:19] Add constraint Constraint: If a BIND(C) attribute is specified, the variable shall be declared in the specification part of a module. The variable shall not be explicitly initialized, it shall not have the POINTER attribute, the ALLOCATABLE attribute, appear in an EQUIVALENCE statement or be a member of a common block. 5. [84:33] Add new paragraph. 5.1.2.15 BIND attribute The BIND attribute specifies that the variable interoperates with a C variable with external linkage, as specified in 16.2.7. Edit number 6 refers to both global data and name mangling syntax. 6. Add after [88:26] and renumber following sections and syntax rules 5.2.13 BIND statement R535 bind-stmt is BIND(C [, NAME = scalar-char-initialization-expr] [, BINDNAME= scalar-char-initialization-expr) [::] bind-entity-list R536 bind-entity is object-name or / common-block-name / The BIND statement specifies the BIND attribute (5.1.2.15) for all objects named in the bind entity list. 7. [411:35] Add paragraph 16.2.7 Interoperation with C global variables A C variable with external linkage interoperates with a variable declared in the scope of a module or with a common block. The BIND(C) attribute shall only be specified for a variable if it is declared in the scope of a module. The variable shall interoperate with a C variable that has external linkage. Only one variable that is associated with a particular C variable with external linkage is permitted to be declared within a program. If a common block is specified in a BIND(C) statement, it shall be specified in a BIND(C) statement in all scoping units in which it is declared. A C variable with external linkage interoperates with a common block that has been specified in a BIND(C) statement, if the C variable is of a struct type and the variables that are members of the common block interoperate with corresponding components of the struct type, or if the common block contains a single variable, and the variable interoperates with the C variable. A variable in a common block specified in a BIND(C) statement shall not be explicitly initialized and it shall not be the parent object of an equivalence-object in an EQUIVALENCE statement (5.5.1). If a variable has the BIND(C) attribute, it has the SAVE attribute as well. A variable with the BIND(C) attribute is a global entity of a program (14.1.1). Such an entity shall not be declared in more than one scoping unit of the program. NOTE 16.17 The following are examples of the usage of bind(c) for variables and for a common block: module example_1 integer, bind(c) :: i integer :: j, k bind(c) :: j end module example1 program example_2 common /com/ k bind(c) :: /com/ ... end program example2 END NOTE 16.17