To: J3 J3/19-114 From: Bill Long Subject: Problems with C_FUNLOC and C_F_PROCPOINTER being PURE Date: 2019-January-18 1. Introduction In 18.2.3.1p1 we say "The C_F_POINTER subroutine is impure; all other procedures in the module are pure.", where the module referenced is the ISO_C_BINDING intrinsic module, which is the topic of subclause 18.2. This implies that 18.2.3.4 C_F_PROCPOINTER (CPTR, FPTR), and 18.2.3.5 C_FUNLOC (X) are both PURE. However, there are undesirable side effects of these two functions being PURE, and making them PURE was likely an oversight. 2. Interpretation Request ---------------------------------------------------------------------- NUMBER: F18/xxxx TITLE: Problems with C_FUNLOC and C_F_PROCPOINTER being PURE KEYWORDS: C_FUNLOC, C_F_PROCPOINTER, ISO_C_BINDING DEFECT TYPE: Erratum STATUS: Submitted QUESTIONS: 1) Regarding C_FUNLOC (X), In 15.7 Pure procedures, constraint C1590 is: "C1590 The specification-part of a pure subprogram shall specify that all its dummy procedures are pure." In 15.5.2.9 Actual arguments associated with dummy procedure entities, the first paragraph says "If the interface of a dummy procedure is explicit, its characteristics as a procedure (15.3.1) shall be the same as those of its effective argument, except that a pure effective argument may be associated with a dummy argument that is not pure and an elemental intrinsic actual procedure may be associated with a dummy procedure (which cannot be elemental)." If C_FUNLOC is PURE, then these together imply that the actual argument, X, has to be a PURE procedure. This is not stated in the specification of this function in 18.2.3.5. This has the effect of limiting the uses of C_FUNLOC compared to the specification in Fortran 2008. This is not indicated in 4.3.3 Fortran 2008 compatibility. Was this an intentional change, or was making C_FUNLOC PURE a mistake? 2) Regarding C_F_PROCPOINTER (CPTR, FPTR), a similar argument to that above implies that the INTENT(OUT) procedure pointer, FPTR, is a PURE procedure. However, there is no stated requirement that the input argument CPTR be PURE, and indeed there is no specification of what that even means if CPTR is a pointer to an interoperable C function. This suggests that C_F_PROCPOINTER provides a backdoor allowing an impure procedure to appear to be pure, invalidating the assumptions that are associated with a pure procedure. Was making C_F_PROCPOINTER a PURE a mistake? ANSWER: Making C_FUNLOC and C_F_PROCPOINTER PURE was a mistake. Edits are included to correct this error. EDITS to 18-007r1: [469:26-27] In 18.2.3 Procedures in the module, 18.2.3.1 General, second sentence, change "C_F_POINER subroutine is" to "C_F_POINTER and C_F_PROCPOINTER subroutines and the C_FUNLOC function are". Making the whole sentence read "The C_F_POINTER and C_F_PROCPOINTER subroutines and the C_FUNLOC function are impure; all other procedures in the module are pure." SUBMITTED BY: Bill Long HISTORY: 19-xxx m218 Submitted ---------------------------------------------------------------------- === END ===