09-296
To: J3
From: Malcolm Cohen
Subject: Interp request on functions returning procedure pointers.
Date: 2009 November 04
----------------------------------------------------------------------
NUMBER: F03/? (maybe 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:
Straw Vote: (1a)+(2a) or (1b)+(2b).
(1a) Although some of the language of the standard appears to permit a
function to return a procedure pointer, this was a mistake.
Edits are supplied to correct this mistake.
(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.
(2a) Not applicable.
(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 should not be drawn. A clarifying edit is
provided.
EDITS for (1a):
[257:3] After "allocatable," insert "and";
Delete ", and whether it is a procedure pointer".
[280:15+] Insert new constraint
"C1246a The result of a function shall not be a procedure pointer."
EDITS for (1b):
[12:17] Change "The variable that ... the result variable"
to "The entity that ... the function result".
[75:13] After "function result" delete "variable".
[93:16] After "of the result" delete "variable".
[115:7] After "function result" delete "variable".
[280:18-19] After "name of the result" delete "variable".
[280:22] After "name of the result" delete "variable".
[280:31] After "name of the result" delete "variable".
[280:33] After "not specified, the"
Change "result variable"
to "name of the result".
[280:34] After "references to the result" delete "variable".
[280:34-35] Delete "The characteristics ... the result variable.".
[280:36] After "that of its result" change "variable" to "entity".
{Ugh.}
[280:36] Change "is a pointer" to "is a data pointer",
[280:37] After "shape of the result" delete "variable".
[280:38] Change "result variable" to "function result".
[280:39] After "with the result" delete "variable".
[280:40+2] In the first sentence of Note 12.37,
Change "variable" to "entity" twice.
[283:20] After "name of its result" delete "variable".
[283:22] Change "result variable" to "result name".
[283:25] Change "result variables identify the same variable"
to "result names identify the same variable"
and delete ", although their names need not be the same".
{Arguably should be done anyway.}
[287:17] After "The result" delete "variable".
[400:7] "result variable is a scalar"->"result is a scalar object".
[407:8] After "identify the result" delete "variable".
[407:12-13] After "identify the result" delete "variable".
[407:22-23] Change "variable" to "entity" thrice.
{Ugh.}
[415:40] Change "result variables"
to "function results that are variables".
[417:18] Change "of the result"
to "of the result entities if they are variables".
[423:14] "The result variable of a function"
->"The result of a function that returns a data object".
[430:13] "data object"->"data entity".
[434:10] Delete whole line.
EDITS for (2b).
[117:27+] Insert new constraint
"C703 (R701) The shall not be a function reference that
returns a procedure pointer."
[160:17+] Insert new constraint
"C809a (R819) shall not be a function reference that returns
a procedure pointer."
[292:8+] Insert new paragraph
"An argument to an intrinsic procedure other than ASSOCIATED, NULL,
and PRESENT shall be a data object."
EDITS for (3).
[12:19] After "data objects" insert "or procedure pointers".
{Clarify answer to question 3.}
SUBMITTED BY: Malcolm Cohen
HISTORY: 09-295 m190 Submitted
----------------------------------------------------------------------