Internal procedure not allowed as actual argument
Tobias Schlüter
tobias.schlueter@physik.uni-muenchen.de
Sat Jun 30 19:02:00 GMT 2007
Janus Weil wrote:
> Hi all,
> I have a question: why doesn't gfortran allow passing an internal
> procedure as an argument to another procedure, as in this example:
>
>
> subroutine sub
>
> call proc(f1)
> call proc(f2)
>
> contains
>
> real function f1(x)
> ...
> end function f1
>
> end subroutine sub
>
>
> real function f2(x)
> ...
> end function f2
>
>
> If we have a subroutine "proc" that expects an external function as
> its argument, "call proc(f2)" is allowed by gfortran, while "call
> proc(f1)" triggers an error like this:
>
> Error: Internal procedure 'f1' is not allowed as an actual argument at (1)
>
> g95 shows the same behaviour, but ifort doesn't complain about this at all.
> Can anyone tell me what the reason for this restriction is?
Quoting 12.4.1.3. from the F2K draft standard:
"If a dummy argument is a dummy procedure without the POINTER attribute,
the associated actual argument shall be the specific name of an
external, module, dummy, or intrinsic procedure, an associated procedure
pointer, or a reference to a function that returns an associated
procedure pointer. The only intrinsic procedures permitted are those
listed in 13.6 and not marked with a bullet (•). If the specific name is
also a generic name, only the specific procedure is associated with the
dummy argument."
Note that internal procedures are not mentioned. The idea behind this
is that it is hard to make the local variables of the containing
procedure visible to the contained procedure when it's called from
somewhere else.
Cheers,
- Tobi
More information about the Fortran
mailing list