09-233 To: J3 From: John Reid Subject: Iterp F95/0098 Date: 2009 May 7 This is an edited version that now refers to Fortran 2003. NUMBER: F95/0098 TITLE: Are dummy functions returning assumed-length character legal? KEYWORDS: DUMMY FUNCTION, ASSUMED-LENGTH CHARACTER DEFECT TYPE: Interpretation STATUS: J3 consideration in progress QUESTION: Are dummy functions returning assumed-length character legal? Consider the following program: character*5 f external f call ss3(f) end subroutine ss3(ff) character*(*) ff, a*10 external ff a = ff()//'99999999' print *, '<', a, '>' end function f() character*(*) f f = '123' end The issue is the call to the dummy function 'ff' in subroutine 'ss3'. Some compilers issue an error message. Others print the result: <123 99999> There appear to be two relevant, contradictory passages in the F2003 standard. Refer to section 4.4.4.1. <> means italics, [] means obsolescent font. C417 says "A function name shall not be declared with an asterisk unless it is of type CHARACTER and is the name of the result of an external function or the name of a dummy function. At the end of the section, there is the text "A char-length type parameter value of * has the following meaning: (1) ... (2) ... (3) ... (4) [If used to specify the character length parameter of a function result, any scoping unit invoking the function shall declare the function name with a character length parameter value other than * or access such a definition by host or use association. When the function is invoked, the length of the result variable in the function is assumed from the value of this type parameter.]" According to the standard, the use in the example program is legal, because 'ff' is the name of a dummy function. But it seems clear that the standard intended that the length of the variable returned by a character function be known at compile time; it is not known in the case where the function is a dummy function. ANSWER: The program does not conform with the standard because of the rule in item (4) in the final paragraph of 4.4.4.1, which is quoted above. The function f is invoked from the scoping unit of ss3 within which the function is declared with a character length parameter value of *. EDITS: None. 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 ................................ John Reid NO vote on 000098 This is different from interpretation 6 since the function has assumed character length, which means that item (3) of page 51 applies. Hence, I think the ANSWER should be The program does not conform with the standard because of the rule in item (3) of the list in 5.1.1.5. The function f is invoked from the scoping unit of ss3 within which the function name does not satisfy any of the required conditions. Malcolm Cohen NO vote on F95/000098 I agree with John that there is an issue here which is not adequately covered by Interp F95/000006. However, I think that the suggestion that item (3) of 5.1.1.5 means that the program is invalid is without merit. A literal interpretation of item (3) means that even if subroutine SS3 declared dummy FF as being CHARACTER*5, the program would still be invalid since the name of the function is F, not FF. This would be a completely ridiculous result. Thus item (3) of 5.1.1.5 is faulty and an edit is required for it to handle (assumed-length) dummy functions at all.