09-264 To: J3 From: Malcolm Cohen Subject: New interp request Date: 2009 July 27 1. Introduction This paper contains an interpretation request for Fortran 2003. The proposed answer has already been applied to Fortran 2008, so if the proposed answer to the request is rejected then an entry needs to be made to page xiv of 09-007r2. 2. Interpretation Request NUMBER: TITLE: Are subroutines distinguishable from arrays? KEYWORDS: Generic resolution, subroutine, array DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Can a subroutine be used as a disambiguator in a generic reference? A subroutine cannot reliably be distinguished from a scalar function because of implicit typing. However, it can always be distinguished from an array function, because an array function needs to have an explicit interface that provides its rank (and type, but rank is the important consideration for this question). For generic resolution, the Fortran 95 standard allowed a dummy argument to be a "disambiguator" if it had a different data type, kind type parameter, or rank (14.1.2.3, page 277). There is no clear definition of what the rank of a subroutine is, but many have assumed that the rank of a subroutine is zero; thus allowing "subroutine vs. array" to be used to disambiguate generic references. However, this text was changed in Fortran 2003 to forbid a subroutine from ever being used as a disambiguator (16.2.3, page 407). Here is an example: Module example Interface gen Module Procedure invoke,aprint End Interface Contains Subroutine invoke(s) External s Call s ! We know this is a subroutine. End Subroutine Subroutine aprint(a) Real a(:) Print *,'[',a,']' End Subroutine End Module It is clear that if the Call s statement were changed to Print *,s() then the module would be standard-conforming. It seems inconsistent to allow scalar functions to disambiguate with arrays but to disallow subroutines from disambiguating with arrays. DISCUSSION: In Fortran 2003, procedureness is a potential disambiguator which would make the above simple example conforming, but there is still a problem with Subroutine invoke(s,n) External s Call s(n) ! We know this is a subroutine. End Subroutine Subroutine aprint(af) Interface Function af(n) Real af(n) End Function End Interface Print *,'[',af(n),']' End Subroutine Again, changing "Call s(n)" to "Print *,s(n)" would make the example conform to the standard as written. ANSWER: This inconsistency was inadvertant. Edits are supplied to correct this oversight. EDITS: [407:28] After "distinguishable if" insert "one is a subroutine and the other is an array, or if". SUBMITTED BY: Malcolm Cohen. HISTORY: 09-264 m189 Submitted 3. Edits to 09-007r2 (potential addition to 09-257) After the inserted "Procedureness ... resolution." insert new sentence "A subroutine is treated as distinguishable from an array function in generic resolution." ===END===