09-236 To: J3 From: Tobias Burnus Subject: Procedure(), pointer: subroutine vs. function and implicit typing Date: 2009 May 11 References: 04-007 NUMBER: TBD TITLE: Procedure(), pointer: subroutine vs. function and implicit typing KEYWORDS: proc-pointer, implicit typing, referencing of procedures DEFECT TYPE: TBD STATUS: TDB QUESTION: 1. Implicit typing of procedure pointer components Regarding the following program program implicitPPC external proc type t procedure(), pointer, nopass :: ptr end type t type(t) :: i i%ptr => proc print *, i%ptr() end program implicitPPC (a) Is the program valid and - if it is - (b) what is the type of "i%ptr"? In J3/04-007 one finds (p. 93, ll. 8-11) 5.3 "Any data entity that is not explicitly declared by a type declaration statement, is not an intrinsic function, and is not made accessible by use association or host association is declared implicitly to be of the type (and type parameters) mapped from the first letter of its name, provided the mapping is not null." [6.1.2 Structure components] (p. 105, ll. 1-2) "R612 data-ref is part-ref [ % part-ref ] ... R613 part-ref is part-name [ ( section-subscript-list ) ]" 2. Procedure pointers pointing to subroutines and functions Given the following subroutine subroutine ppOne(do_the_subroutine) logical :: do_the_subroutine external some_subroutine, some_function procedure(), pointer :: proc_pointer if (do_the_subroutine) then proc_pointer => some_subroutine call proc_pointer(5) else proc_pointer => some_function y = proc_pointer(7) end if end subroutine ppOne (a) Does the subroutine ppOne conform to the Fortran standard? (b) If yes, does a subroutine with the "if"/"else"/"end if" lines removed conforms to the standard? In J3/04-007 one finds (p. 145, ll. 2-4) 7.4.2.2 "If proc-pointer-object has an implicit interface and is explicitly typed or referenced as a function, proc-target shall be a function. If proc-pointer-object has an implicit interface and is referenced as a subroutine, proc-target shall be a subroutine." 3. Assignment of procedure pointers and interface conformance (a) Is the following program valid? IMPLICIT NONE ! p is not implicitly typeable real, external :: func procedure(), pointer :: p p => func end (b) Is the following modified program valid implicit none real, external :: func procedure(), pointer :: p1 procedure(REAL), pointer :: p2 real :: y p1 => func ! (A) p2 => p1 ! (B) y = p2() end In J3/04-007 one finds (p.146, ll. 36-38; p. 145, ll. 2-6) 7.4.2.2 Procedure pointer assignment "If the proc-target is not a pointer, proc-pointer-object becomes pointer associated with proc-target. Otherwise, the pointer association status of proc-pointer-object becomes that of proc-target; if proc-target is associated with a procedure, proc-pointer-object becomes associated with the same procedure. [...] If proc-pointer-object has an implicit interface and is explicitly typed or referenced as a function, proc-target shall be a function. If proc-pointer-object has an implicit interface and is referenced as a subroutine, proc-target shall be a subroutine. If proc-target and proc-pointer-object are functions, they shall have the same type; corresponding type parameters shall either both be deferred or both have the same value." ANSWER: To question 1: The program is valid and i%ptr is declared implicitly to be of the type REAL as the name of the data entity starts with a "p". EDITS: SUBMITTED BY: Tobias Burnus