Internal procedures as dummy arguments in gfortran?

Daniel Kraft d@domob.eu
Wed Sep 23 11:12:00 GMT 2009


Daniel Kraft wrote:
> Paul Richard Thomas wrote:
>> To my astonishment, given some of the remarks, changing the error to
>> an error on notification works just fine on FC9/i386 :-)
> 
> Have you tried this with some kind of more complicated stuff?  I'm no
> expert on using PROCEDURE and procedures as actual arguments, but
> something along:
> 
> ABSTRACT INTERFACE
>   INTEGER FUNCTION myproc ()
>     IMPLICIT NONE
>   END FUNCTION myproc
> END ABSTRACT INTERFACE
> 
> ...
> 
> IMPLICIT NONE
> 
> ...
> 
> SUBROUTINE sub1 (proc)
>   PROCEDURE(myproc) :: proc
>   CALL sub2 (proc)
should be CALL sub3 (proc)
> END SUBROUTINE sub1
> 
> SUBROUTINE sub2 (p1, p2)
>   PROCEDURE(myproc) :: p1, p2
>   PRINT *, p1 () ! Should be 1
>   PRINT *, p2 () ! Should be 2
> END SUBROUTINE sub2
> 
> RECURSIVE SUBROUTINE sub2 (proc)
should be sub3 of course
>   PROCEDURE(myproc), OPTIONAL :: proc
> 
>   INTEGER :: a
> 
>   IF (PRESENT (proc))
>     a = 2
>     CALL sub2 (proc, internal_proc)
>   ELSE
>     a = 1
>     CALL sub1 (internal_proc)
>   END IF
> 
> CONTAINS
> 
>   INTEGER FUNCTION internal_proc ()
>     internal_proc = a
>   END FUNCTION internal_proc
> 
> END SUBROUTINE sub3
> 
> At least I would expect this to behave as indicated by the comments,
> though I've not checked with the standard.  I'd be very surprised if
> that worked just out-of-the-box, too, when disabling the error.  But you
> could try!  If it does, I guess we can claim this F2008 feature
> implemented :D
> 
> Daniel
> 


-- 
Done:  Arc-Bar-Cav-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri



More information about the Fortran mailing list