J3/13-249 To: J3 From: Malcolm Cohen Subject: Interp F03/0139 Date: 2013 February 14 ---------------------------------------------------------------------- NUMBER: F03/0139 TITLE: Functions returning procedure pointers KEYWORDS: procedure pointer DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: (1) Is a function permitted to return a procedure pointer? Much of the language talks about the function result variable, but a procedure pointer is not a variable. For example, 2.2.3 says [12:16] "The VARIABLE that returns the value of a function is called the RESULT VARIABLE." (emphasis mine); which indicates that the value of a function is returned in a variable. (2) Where may a function reference that returns a procedure pointer appear? In particular, (a) as a in a SELECT TYPE or an ASSOCIATE statement; (b) within parentheses as a primary; (c) as the argument to an intrinsic inquiry function such as KIND or LEN. (3) [12:18-19] says "a subroutine may be used to change the program state by changing the values of any of the data objects accessible to the subroutine". A procedure pointer is not a data object, so is this meant to imply that a subroutine is not permitted to change the state of a procedure pointer? Similar text for functions appears in the same paragraph. ANSWER: (1b) Yes, a function is permitted to return a procedure pointer; the text calling this a variable is in error. Edits are supplied to correct these mistakes. (2b) It was intended that a function reference that returns a procedure pointer only be permitted as an argument to the ASSOCIATED and NULL intrinsic functions and in places where an ordinary procedure name would be acceptable. Parentheses around a pointer act to dereference the pointer and return a copy of the value: this action is inapplicable to procedures. Thus the answers to the specific sub-questions are No, No, and No again. Clarifying edits are provided. (3) No, this implication is not intended. A clarifying edit is provided. EDITS for (1b): [10:33+] Insert new term after "1.3.77 <>" "1.3.77a <> entity that returns the value of a function". [15:31-33] Delete term 1.3.121 <>. [52:2] 4.3.1.2p2, after "function result" delete "variable". [58:23] 4.4.3.2p5, "result variable in the function" -> "function result". [87:9] 5.1p2 "its result variable" -> "the function result". [109:24] 5.5p4, "name of the result variable of that function subprogram" -> "result of that function". {Function *subprogram*s do not have results, the function specified by the FUNCTION statement does, as do the ones defined by the ENTRY statements, but the subprogram is just syntax.} [112:15] 5.7.1.1 C587, "result variable" -> "function result". [114:22] 5.7.2.1 C5100, "result variable" -> "function result". [130:26] 6.7.3.2p2, after "function result" delete "variable". [278:11] 12.3.1 "result value"->"function result". {Reads a bit awkwardly, but it is important to use the correct terms and to be consistent with 12.3.3 (which does) otherwise this is undefined meaningless blather.} [307:5,9] 12.6.2.2p3, "result variable" -> "function result", twice. [307:12,14,15] p4, "result variable" -> "function result", thrice. [307:15-16] Delete "The characteristics ... variable.". [307:18,18,20] "result variable" -> "function result", thrice. [307:20+2] NOTE 12.41, "The ... subprogram." -> "The function result is similar to any other entity (variable or procedure pointer) local to the function subprogram.". [307:20+4] "this variable" -> "this entity". [307:20+5] "that variable" -> "that entity". [309:23,24] 12.6.2.5p3, "result variable name" -> "name of the function result", twice. [310:2] 12.6.2.6p3, after "name of its result" delete "variable". [310:2-3] Delete "The characteristics ... the result variable.". [310:5-6] "result variables identify the same variable" -> "result names identify the same entity" and delete ", although their names need not be the same". [310:6] "scalars" -> "scalar variables". [314:3] After "The result" delete "variable". [433:7] "result variable is a scalar"->"result is a scalar entity". [441:7,10] 16.3.1p4, "result variable" -> "function result", twice. [441:18-20] 16.3.3p1, "result variable" -> "function result", thrice. [449:3-4] 16.5.3.1p1 "result variables" -> "function results that are variables". [450:20] 16.5.3.4p6, "result variables" -> "function results that are variables". [456:11] 16.6.6p1, item (15)(e), "the result variable of a function" -> "a variable that is the function result of that procedure" {Also fixes all function results becoming undefined when a single procedure is invoked!} EDITS for (2b). [133:26+] Insert new constraint "C702a (R701) The shall not be a function reference that returns a procedure pointer." [170:23+] Insert new constraint "C804a (R805) The shall not be a function reference that returns a procedure pointer." [316:12+] 13.2.1 after p6, insert new paragraph "An argument to an intrinsic procedure other than ASSOCIATED, NULL, or PRESENT shall be a data object." EDITS for (3). [30:28] After "data objects" insert "or procedure pointers". SUBMITTED BY: Malcolm Cohen HISTORY: 09-295 m190 F03/0139 submitted - Passed by J3 meeting: B answers passed 10-105 m191 Passed as amended by J3 letter ballot #20 09-307 N1816 m191 Failed WG5 ballot #7 {N1805/6} - interp updated - see 10-135r1 13-nnn m200 Revised ----------------------------------------------------------------------