J3/02-136 Date: 21 February 2002 To: J3 From: John Reid Subject: Edits re interfacing with C Here are some edits that I have prepared after reading the parts of the draft standard that concern interfacing with C. I have addressed several J3 internal notes. In particular, I propose that 'interoperability' of a type and type parameters, procedure or variable is a property determined by the Fortran syntax independently of whether there is any corresponding C entity. I wish that the BIND(C) attribute and 'interoperable' could mean the same thing. They do for procedures and derived types. For a variable, however, the BIND(C) attribute is an extra property that makes it global. EDITS 42:9-10. Replace by C420 (R423) If BIND(C) appears, each component shall be a data entity and of a type and type parameters that is interoperable (15.2). 67:30. Change to . [This is a different from that of the next 3 constraints.] 67:34. After 'variable' add 'and its type and type parameters shall be interoperable (15.2). 73:1,2,7,8,Note5.11 and in many other places. Change 'BIND attribute' to 'BIND(C) attribute'. [BIND(C) is already used elsewhere, reminds the reader of what we are doing and allows for future bindings to other languages - an entity with the BIND(C) attribute might not have the BIND(other) attribute.] 73:1-4. Replace by 5.1.2.4 BIND(C) attribute for data entities The BIND(C) attribute for a variable or common block specifies that it is interoperable with a C variable with external linkage (15.2.7). and delete the J3 internal note. [See, also, edit for 270:6+]. 73:7-8. Delete sentence 'The ... (15.2.7).' [Made into constraints.] 83:1. After 'module' add 'and shall be of a type and type parameters that is interoperable (15.2)'. 83:3+. Add C558a (R526) If a is a common block, each variable of the common block shall be of a type and type parameters that is interoperable (15.2). 250:9,22,25,26. Change to . 250:24. Delete ', '. 264:22. Replace 'or ... parameters' by 'optional, a procedure, or of a type and type parameters that is not interoperable (15.2)'. 264:23-24. Delete. [Replaced by constraint.] 266:NOTE 12.41. Add to first use statement: ', ONLY: C_INT, C_FLOAT 267:2. Replace 'of ... parameters' by 'optional, a procedure, of a type and type parameters that is not interoperable (15.2)'. 268:11+. Add C1259a (R1234) A shall not be specified if any dummy argument is an assumed-shape array, polymorphic, optional, a procedure, of a type and type parameters that are not interoperable (15.2), or an asterisk. 269:37-40. Delete sentence 'If ... letters.'. [Not needed since an entry statement defines a procedure, so the words in the rest of the paragraph apply.] 270. Delete J3 internal note. [See previous edit.] 270: NOTE 12.43. Add INTERFACE END INTERFACE around the code. [Make it a valid code fragment.] 270:6+. Add 12.5.3.1 BIND(C) attribute for procedures The BIND(C) attribute for a procedure specifies that it is interoperable with a C function with external linkage. 371:13-17&19-23. Replace 'C_INT ... C_BOOL' by 'the named constants of type default integer listed in Table 15.1' and delete lines 19-23. [It is very hard to read long lists like this - much easier to read the Table.] [C_BOOL is missing from lines 19-23. I have assumed that this is a mistake.] 371. Delete J3 internal note. [See edits that add only clauses to examples.] 372:2,4. Move 'C_SIGNED_CHAR' up to follow 'C_LONG_LONG'. Alternatively, move the 'C_SIGNED_CHAR' row in Table 15.1 down. [Easier to read if the order is the same in the two places.] 372:16. Move line to follow NOTE 15.2. [Easier to read if the order is the same as in Table 15.1.] 372:28-31. Replace by An intrinsic type and type parameters is <> if it is listed in Table 15.1, the kind value is not -1, and the character length is 1 if the type is CHARACTER. A derived type is <> if it has the BIND(C) attribute (4.5.1). A procedure is <> if it has the BIND(C) attribute (12.3.2.3, 12.5.2.1, 12.5.2.2, 12.5.2.4). A scalar variable is <> if it is of a type and type parameters that is interoperable. An array variable is <> if it is of assumed-size or explicit-shape and of a type and type parameters that is interoperable. NOTE 15.2a The syntax rules and their constraints require that a derived type that is interoperable has components that are all data objects that are interoperable. No component is permitted to be a procedure or allocatable, but a component of type C_PTR may hold the C address of such an entity. The rules and their constraints also require that a procedure that is interoperable has dummy arguments that are all data objects that are interoperable. No dummy argument is permitted to be a procedure or allocatable, but a dummy argument of type C_PTR may hold the C address of such an entity. The function C_LOC may be used to find the C address of a procedure or allocatable object and the subroutine C_F_POINTER may be used to establish a Fortran pointer whose target has a given C address. For an entity that is interoperable, an equivalent entity is declarable in a C program and the Fortran entity is said to be <> with the C entity. 373:2. Change the first sentence to 'Table 15.1 shows all the combinations of type and type parameters that are interoperable and the corresponding C types.' 373:3. Change 'names' to 'named integer constants'. [I think it is entities that are accessed, not names.] 373:10. Change 'length ... one' to 'character length of the Fortran entity is one'. 373:NOTE 15.4. At the front of the last line, add 'NOTE 15.18'. 374:NOTE 15.6, lines 4-5. Change 'C_UNSIGNED_INT, ... C_UNSIGNED_CHAR' to 'for their kind type parameter values'. [As far as I can see, these names are not defined.] 374:NOTE 15.8. Delete this note. 374:5. Change first sentence to 'A C procedure argument is often defined in terms of a <>. [We clearly need the term.] 374:7,9. Change '"C address"' to 'C address'. 375:NOTE 15.9. Change the first use statement: USE ISO_C_BINDING, ONLY: C_PTR, C_FLOAT, C_ASSOCIATED, C_LOC 377:J3 internal note. Delete. [I believe that the changes I propose adequately address this problem. See, in particular, the new 15.2 text.] 377:3-4. On line 3, change 'A Fortran procedure interface' to 'A procedure that has the BIND(C) attribute (12.5.3)'. Delete line 4. 377:12-13 and 378: J3 internal note. Delete. [That dummy arguments be data objects is now in constraints. NOTE 12.6 makes it clear that C_LOC must be employed to pass procedures.] 379:NOTE 15.18. Change the first use statement: USE ISO_C_BINDING, ONLY: C_CHAR, C_NULL_CHAR 379:3. Change 'with' to 'within'. 398:37,38-39. Change 'all ... undefined' to 'any variable of type C_PTR becomes undefined if its value was obtained by a call of C_LOC for that variable or any variable that was then associated with that variable'. [We do not want to introduce a new form of association.] 457:2,7,42. Remove '}' at line end. 457:34. Change to: USE ISO_C_BINDING, ONLY: C_INT, C_FLOAT, C_LOC