J3/99-205r1 Date: 1999/08/25 To: J3 From: /interop 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. This paper describes the syntax for the sharing of global data between Fortran and C. Note that this paper does not address the issues with BINDNAME= that were raised in 99-211, which the committee discussed yesterday. B. Edits Edits refer to J3/99-007R2 Add BIND statements to the list of specification statements: [10:36+] Add to R214 "<> " Add the BIND attribute to the list of attributes in a type declaration. [70:2+] Add to R504 "<> " This was a place-holder note to remind us to add interop. with C global data. [70:9-11] Delete J3 note 147 Constraints on the use of the BIND attribute in a type declaration stmt. [71:19+] Add the following constraints: "Constraint: A shall appear only in the of a module. Constraint: If a is specified, the POINTER, PARAMETER, ALLOCATABLE, EXTERNAL, or INTRINSIC attribute shall not be specified. The entity declared shall be a variable. Constraint: If a with a appears, the shall not contain more than one ." An object with BIND can't have initialization. [71:6] After "an intrinsic name" add ", an object with the BIND attribute, an object in a named common block that has the BIND attribute" An object with BIND can't be initialized in a DATA statement. [89:15] After "an automatic object" add ", an object with the BIND attribute, an object in a common block that has the BIND attribute" BNF for the BIND attribute. [84:33+] Add new subsection, and move the BNF for here (as suggested) to eliminate the long forward reference. "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. R5xx <> BIND(C[, ]) [[ Move text for R1224 [283:25-26] here.]] Constraint: A shall not contain more than one NAME= specifier. Constraint: A that appears in a BIND statement or a type declaration statement shall not contain more than one BINDNAME= specifier. [[Move the constraint on [284:25] here, and change "" to "".]] The BIND attribute shall not be specified for a variable or common block that cannot interoperate with some C variable with extern linkage. An entity with the BIND attribute also has the SAVE attribute." Introduce the BIND statement [88:26+] Add new section, and renumber subsequent sections "5.2.xx BIND statement R535 <> [::] R536 <> <> / / Constraint: If any in a is an , the shall appear in the specification part of a module. The BIND statement specifies the BIND attribute (5.1.2.15) for a list of entities." An object with BIND(C) can't appear in EQUIVALENCE [94:39] After "a result name" add ", a variable with the BIND attribute, a variable in a common block that has the BIND attribute" An object with BIND(C) can't appear in a COMMON block [97:3] After "an entry name" add ", a variable with the BIND attribute" [283:24] Change "BIND(C [, ])" to "" The following J3 note was handled by the edits to [84:33+] [283:28-37] Delete J3 note 155. The following four changes try to tidy up some information on global entities. [361:12+] Add the new list item (and fix up the ", or" and "." preceding) "(6) A binding label (14.x)." [415:19+] Add the following glossary entry "<> (12.5.2.7, 16.2.7.1): A value of type default character that uniquely identifies how a variable, common block, subroutine or function is known to a companion processor." [418:5] After "a " add ", a " [369:4+] Add the following new section, and renumber subsequent sections "14.x Scope of a binding label A binding label (12.5.2.7, 16.2.7.1) is a global entity. Within a program, the name of a global entity shall not be the same as the binding label of a different global entity." [411:35+] Add the following new section "16.2.7 Interoperation with C global variables A C variable with external linkage may interoperate with a variable declared in the scope of a module or with a common block. A variable that is specified to have the BIND attribute shall interoperate with a C variable that has external linkage. At most one variable that is associated with a particular C variable with external linkage is permitted to be declared within a program. [[Add J3 note]] As with procedural interoperability, we need to make it clear whether there must be such a C variable, or whether everything can be defined by Fortran alone. In addition, we still need to draw a distinction between interoperating as a matching of a C type to a set of Fortran type and attributes as opposed to interoperating meaning that the Fortran and C things are "linked". [[End J3 note]] If a common block is specified in a BIND statement, it shall be specified in a BIND statement with the same binding label in each scoping unit 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, (1) 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 (2) if the common block contains a single variable, and the variable interoperates with the C variable. NOTE 16.17 The following are examples of the usage of the BIND attribute for variables and for a common block. The Fortran variables, C_EXTERN and C2, interoperate with the C variables, c_extern and myVariable, respectively. The Fortran common blocks, COM and SINGLE, interoperate with the C variables, com and single, respectively. MODULE LINK_TO_C_VARS USE ISO_C_BINDING INTEGER(C_INT), BIND(C) :: C_EXTERN INTEGER(C_LONG, NAME='myVariable') :: C2 BIND(C) :: C2 COMMON /COM/ R, S REAL(C_FLOAT) :: R, S, T BIND(C) :: /COM/, /SINGLE/ COMMON /SINGLE/ T END MODULE LINK_TO_C_VARS int c_extern; long myVariable; struct {float r, s;} com; float single; END NOTE 16.17 16.2.7.1 Binding labels for common blocks and variables The <> of a variable or common block is a value of type default character that specifies the name by which the variable or common block is known to the companion processor. If a variable or common block had the BIND attribute specified with a NAME= specifier, the binding label is the value of the expression specified for the NAME= specifier. The case of letters in the binding label is significant, but leading and trailing blanks are ignored. If a variable or common block had the BIND attribute specified without a NAME= specifier, the binding label is the same as the name of the entity using lower case letters. The binding label of a C variable with extern linkage is the same as the name of the C variable. A Fortran variable or common block with the BIND attribute that has the same binding label as a C variable with extern linkage is associated with that variable. [[Add J3 note]] We need details here (or elsewhere) about how changes to the C variable affect the Fortran thing, and vice versa. This is something that also affects procedure interoperability. We also need to specify how the variables in the common block "line up" with members of the C struct. Does simply relying on the concept of storage association work? [[End J3 note]] The meaning of the expression following a BINDNAME= specifier is processor dependent." Add the following Index entries: <> [[ref to R5xx (added above)]] BIND statement [[ref to 5.2.xx (added above)]] [[ref to 5.2.xx (added above)]] [[ref to 5.1.2.15 (added above)]] [[ref to 5.1.2.15 (added above)]] Change the index entry for "NAME= specifier 218" to "NAME= specifier, in the INQUIRE statement 218 in the [[ref to 5.1.2.15 (added above)]]" [290:12+] Add the following sentence to Note 156. "See also 16.2.7.1, which also has similar text referring to BINDNAME=."