09-263 To: J3 From: Malcolm Cohen Subject: Interp F95/0098 Date: 2009 July 26 1. Introduction This is an edited version that now refers to Fortran 2003. The question has been completely rewritten, with an extra related example that needs to be considered at the same time. (The alternative to a wholesale rewrite would be to subsume the interp into a whole new one, but that seems unnecessary.) 2. Interp NUMBER: F95/0098 TITLE: Are dummy functions returning assumed-length character legal? KEYWORDS: Dummy function, assumed-length character DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: (1) Is a dummy function allowed to have assumed character length? (2) If so, can it be invoked directly from that scoping unit? (3) If so, is this still true if the invoked function itself has a result variable that is assumed-length (this is obsolescent). (4) If an assumed-length function is declared in another scoping unit as a specific length, can it be passed as an actual argument that corresponds to a dummy function of that specific length and be invoked via the dummy function? (5) Clarification request - see discussion - Example 1 does not have any external function with assumed character length, so does it use any obsolescent feature or not? Example 1 (for questions 1 and 2): PROGRAM EX1 CHARACTER F*5 EXTERNAL F CALL S(F) END SUBROUTINE S(D) CHARACTER D*(*) PRINT *,D() END CHARACTER*5 FUNCTION F() F = 'OK' END Example 2 (for question 3): The same as example 1 except for F which is assumed-length, making the whole example 2: PROGRAM EX2 CHARACTER F*5 EXTERNAL F CALL S(F) END SUBROUTINE S(D) CHARACTER D*(*) PRINT *,D() END CHARACTER*(*) FUNCTION F() F = 'OK' END Example 3 (for question 4): The same as example 3 except that S declares the dummy function with a specific length, making it: PROGRAM EX3 CHARACTER F*5 EXTERNAL F CALL S(F) END SUBROUTINE S(D) CHARACTER D*5 PRINT *,D() END CHARACTER*(*) FUNCTON F() F = 'OK' END DISCUSSION: Examples 2 and 3 use the obsolescent feature of "assumed length character for an external function". It seems ambiguous whether example 1 uses an obsolescent feature: by C416 and the text of 4.4.4.1 it would apparently not be obsolescent but by C417 it would appear to be obsolescent. Example 1 does not use any feature described in Annex B, which implies that it is not obsolescent. It would be nice to clarify this. A straightforward reading of the literal words of the standard appears to indicate that example 1 is standard-conforming, but that example 2 is not valid due to it violating item 4 of the list at the end of subclause 4.4.4.1 (page 41). Similarly, example 3 would appear to be invalid by the same rule: this last certainly seems counter-intuitive, but does seem to be what the standard literally says. The basic issue underlying examples 1 and 2 is that the standard says "If used to declare a dummy argument of a procedure, the dummy argument assumes the length of the associated actual argument." It has been argued that this should only apply to dummy variables and not to dummy functions, but that is not what the standard says. ANSWER "literal": (1) Yes, a dummy function is allowed to have assumed length; this is clearly implied by the permission given in C417. (2) Yes, there is no prohibition against invoking such a function. (3) No, an external function whose result variable is assumed-length shall only be invoked from a scoping unit that declares that function by name as having a specific length, or which accesses such a declaration by use or host association. This is clearly stated in item (4) of the list at the end of subclause 4.4.4.1. (4) No, that example is also invalid by the same reasoning: although S declares the dummy argument D with length 5, it does not declare the actual function F with length 5. (5) The implication of constraint C417 that a dummy function having assumed length is obsolescent is a typographical error: an edit is provided to correct this. EDITS "literal": [41:11-12] In C417, change "\obs{unless ... dummy function}" to "unless it is of type CHARACTER and is the name of a dummy function \obs{or the name of the result of an external function}". {Note: \obs{...} indicates obsolescent font.} ANSWER "literal + semantic consistency": Same as "literal" for (1), (2) and (5), revised (3) and (4): (3) Yes, the actual invoked function may have an assumed-length result. The prohibition against this in item (4) is an error; an edit is supplied to correct this. (4) Yes, this is also valid. The prohibition against this in item (4) is in error; an edit is supplied to correct this. EDITS "literal + semantic consistency": As per "literal" plus [41:34,36] At the end of 4.4.4.1, item (4), after "invoking the function" insert ", or passing it as an actual argument"; change "host or use" to "argument, host, or use". ANSWER "remove assumed-length dummy functions": The feature has been clearly present since Fortran 90, and apparently present since Fortran 77 (the text of the F77 standard implies the feature, but it is less clear that this was deliberate). However, in hindsight it was a mistake to continue to include this feature which few processors implemented and thus which few programs used. Thus the answers to the questions should be: (1) No, a dummy function is not permitted to have assumed length. (2) N/A. (3) N/A. (4) Yes, this is valid. The prohibition against this in item (4) is in error. (5) Example 1 is not conforming so the question is not applicable. Edits are provided to remove this troublesome feature and to correct the mistake in item (4) at the end of subclause 4.4.4.1. EDITS "remove assumed-length dummy functions": [41:6] In C416, item (1) change "dummy argument" to "dummy variable". [41:12] In C417, delete "or the name of a dummy function". [41:29] In item (1) of the list at the end of 4.4.4.1, change "dummy argument" to "dummy variable", twice. [41:34,36] At the end of 4.4.4.1, item (4), after "invoking the function" insert ", or passing it as an actual argument"; change "host or use" to "argument, host, or use". [437:32+] Insert new paragraph and single-item list: "The Fortran 95 features that are not contained in this standard are the following: (1) Assumed character length dummy functions. In FORTRAN 77, and for consistency also in Fortran 90 and 95, a dummy function was permitted to assume its character length from the associated actual argument." SUBMITTED BY: Larry Meadows HISTORY: 02-157 m160 F95/0098 submitted 04-417r1 m170 Duplicate of interp #6 05-180 m172 Failed WG5 ballot N1617 - not a duplicate of F95 interp 000006 09-233 m188 Revised answer. 09-261 m189 Revised again. 09-263 m189 Rewritten and revised to cover more of the issue. ===END===