Internal procedures as actual arguments or procedure pointer targets
Yvonne Ma 270003Y3PJ Visits (1006)
The Fortran 2008 standard relaxes some rules for internal procedures. Procedure pointers can now point to internal procedures. In addition, you can use internal procedures and pointers to internal procedures as actual arguments. Because an internal procedure has access to the variables of its host procedure, procedure pointers to an internal procedure can only be used before the host procedure completes its execution.
Here is an example of a procedure pointer to an internal procedure:
num_prints = 0
In this contrived example, subroutine work uses procedure pointer iprinter to do its printing. Subroutine sub takes advantage of this to count the number of integers printed by work. The program output is:
Note that calling work after sub has completed its execution is invalid. Module variable iprinter is associated with myprint which accesses host variable num_prints. After sub completes its execution, its stack is freed, including the storage for num_prints.
Support for this Fortran 2008 feature is available in XL Fortran, starting with version 14.1.
Authors: Rafik Zurob, Yvonne Ma