(j3.2006) Function returning procedure pointers

Bill Long longb
Fri Dec 26 00:37:25 EST 2014


On Dec 25, 2014, at 12:07 AM, Malcolm Cohen <malcolm at nag-j.co.jp> wrote:

> Hi folks,
> 
> Why did we pass an interp to make these happen?  They are really horrible, and 
> violate our usual design rule of encapsulating things in derived types when 
> building bigger things - whereas with these one can have a pointer to a function 
> returning a pointer to a function returning a pointer to a function ... 
> (unbounded recursion).


Certainly not a programming style I?d recommend..

> 
> It's not that it's impossible to implement, but it's really horrid.  Does anyone 
> accept the following yet?
> 

I checked the 4 compilers I have available.

Cray accepts it:

> ftn test.f90
> ./a.out
 ok
> 


Intel does not.  The first error message issued was this:

test.f90(8): error #8487: The definition of a function that returns a procedure pointer is not yet supported.   [F1]
   Procedure(f0),Pointer :: f1
??????????????^

which lead to an (expected) cascade of other messages.  Not really an informative test.



gfortran issued just one error message:


 p0 => p1()
       1
Error: Interface mismatch in procedure pointer assignment at (1): PROCEDURE POINTER mismatch in function result

which seems questionable to me.



PGI suffered an ICE.


Cheers,
Bill




> Module junk
> Contains
>  Character(2) Function f0()
>    f0 = 'ok'
>  End Function
>  Function f1()
>    Procedure(f0),Pointer :: f1
>    f1 => f0
>  End Function
>  Function f2()
>    Procedure(f1),Pointer :: f2
>    f2 => f1
>  End Function
>  Function f3()
>    Procedure(f2),Pointer :: f3
>    f3 => f2
>  End Function
>  Function f4()
>    Procedure(f3),Pointer :: f4
>    f4 => f3
>  End Function
> End Module
> Program test
>  Use junk
>  Procedure(f0),Pointer :: p0
>  Procedure(f1),Pointer :: p1
>  Procedure(f2),Pointer :: p2
>  Procedure(f3),Pointer :: p3
>  Procedure(f4),Pointer :: p4
>  p4 => f4
>  p3 => p4()
>  p2 => p3()
>  p1 => p2()
>  p0 => p1()
>  Print *,p0()
> End Program
> 
> Luckily we don't have to handle p4()()()()().  Yet.
> 
> Cheers,
> -- 
> ................................Malcolm Cohen, Nihon NAG, Tokyo. 
> 
> _______________________________________________
> J3 mailing list
> J3 at mailman.j3-fortran.org
> http://mailman.j3-fortran.org/mailman/listinfo/j3

Bill Long                                                                       longb at cray.com
Fortran Technical Suport  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101





More information about the J3 mailing list