To: J3 07-261 From: Bill Long Subject: UTI 124 (p 588): Defective C interop example Date: 2007 July 26 References: J3/07-007r2 (N1678) Discussion There are numerous defects in C12.2 Example of Fortran calling C (15.3). In addition to the problems pointed out in UTI 124, the Fortran example code includes the declaration of an array with both the allocatable attribute and an explicit shape, and the reference to a function using a CALL statement. The unnatural declaration for the dummy argument RECVCOUNTS seems more confusing than informative, and missed the opportunity to illustrate that an allocatable actual argument can correspond to an assumed-size dummy argument, and that the interface is where the interoperability is specified. Finally, the final sentence of para 6 seems to suggest that Note 12.46 is somehow related to this example. In fact, it is just another example. This seems more distracting than helpful. Edits to repair the example are provided below. Edits to 07-007r2: All edits are to subclause C12.2 Example of Fortran calling C (15.3). [587:14] Replace "TYPE(C_PTR) , VALUE :: RECVCOUNTS" with "INTEGER(C_INT) :: RECVCOUNTS(*)" [587:21] Delete the final sentence of para 6: "See also Note 12.46." [587:26-27] Replace para 9 with: "The third C formal parameter is the int pointer recvcounts, which corresponds to the Fortran dummy argument RECVCOUNTS, which is an assumed-size array of type INTEGER(C_INT)." [587:33] Append ", RET" [587:34] Replace ", TARGET :: RECVCOUNTS(100)" with " :: RECVCOUNTS(:)" [587:38-39] Replace the CALL statement with "RET = C_LIBRARY_FUNCTION (C_LOC(SEED), SENDCOUNT, RECVCOUNTS)" [587:41 - 588:1] Replace para 12 with "The preceding code shows an example of how C_Library_Function might be referenced in a Fortran program unit." [588:2-5] Replace para 13 with "The first Fortran actual argument is a reference to the function C_LOC which returns the value of the C address of its argument, SEND. This value becomes the initial value of the first formal parameter, the pointer sendbuf, in C_Library_Function." [588:6-8] Replace para 14 with "The second Fortran actual argument is SENDCOUNT of type INTEGER(C_INT). Its value becomes the initial value of the second formal parameter, the int sendcount, in C_Library_Function." [588:9-13] Replace para 15 with "The third Fortran actual argument is the allocatable array RECVCOUNTS of type INTEGER(C_INT). The base C address of this array becomes the initial value of the third formal parameter, the pointer recvcounts, in C_Library_Function. Note that interoperability is based on the characteristics of the dummy arguments in the specified interface and not on those of the actual arguments. Thus, the fact that the actual argument is allocatable is not relevant here."