I’ve always thought it is forbidden. Only recently I found a disturbing sentence in MFE 2018 (sec. 5.12, p.88):
The actual argument may be a generic procedure name (Section 5.18); if it is also a specific name, only the specific procedure is passed
The second part, after semicolon, is OK, but the generic? How could that be possible? The two compilers I checked (gfortran and ifort) seem not to support generics. Trying to pass log
intrinsic function (which is generic-only name):
intrinsic log, sin
real :: x0, x1, res
call calka(log,x0,x1,res)
results in
5 | call calka(log,x0,x1,res) | 1
Error: Intrinsic ‘log’ at (1) is not allowed as an actual argument
If I change log
to sin
(which is both generic and specific name), it works fine, as expected. Similarly for user-written generic procedure
MODULE swapping
INTERFACE swap
module procedure swapreal, swapinteger
END INTERFACE swap
CONTAINS
SUBROUTINE swapreal(a,b)
...
Attempt to call testsub(swap,...)
results in
Error: Symbol at (1) is not appropriate for an expression
Again, substituting specific swapreal
or swapinteger
makes it work fine.
I checked old MFE 90/95 (2nd edition) which states (sec 5.12, p. 87):
The procedure that is passed must be an external or module procedure and its specific name must be passed when it also has a generic name
Any comments? Am I misinterpreting the clause? Apparently there were some changes to the topic in following Fortran standards, as MFE 90/95 explicitly prohibits internal procedures as arguments, while the 2018 version allows them.
I tried to find relevant info in the Standard, to no success.