Re: Interface Question




A schreef:

Inside of A.f90 looks something like this

INTERFACE
SUBROUTINE C
...................
...................
END SUBROUTINE C
END INTERFACE

Can someone explain what this INTERFACE block is meant for. I know
INTERFACE could be used to achieve "overloading" of operators or
defining generic routines. But I don't understand what's going on here.


The INTERFACE block defines how subroutine C is supposed to be
used. The compiler can then check if the code has a syntactically
correct
call to the subroutine, that is: correct number of arguments, correct
types,
kinds, dimensions, correct order.

Usually this can be avoided by putting the subroutine in a module: it
is safer and easier because the interface is then known automatically
and there is only one place where it is defined - where the routine
itself
is defined.

If, however, subroutine C is a dummy argument, then an explicit
interface is a very useful mechanism: you declare explicitly what
your calling routine expects from any actual subroutine that is passed.

It is also useful if you have subroutines or functions not written in
Fortran
or if you lack the source to put them in a module.

First and foremost: INTERFACE helps the compiler to do the "right"
thing.

Hope this helps.

Regards,

Arjen

.



Relevant Pages