Fortran – explicit interface

“explicit interface” means that the interface to the procedure (subroutine or function) is declared to the compiler. This allows the compiler to check consistency of arguments between calls to the procedure and the actual procedure. This can find a lot of programmer mistakes. You can do this writing out the interface with an interface statement but there is a far easier method: place the procedure into a module and use that module from any other entity that calls it — from the main program or any procedure that is itself not in the module. But you don’t use a procedure from another procedure in the same module — they are automatically known to each other.

Placing a procedure into a module automatically makes its interface known to the compiler and available for cross-checking when it is useed. This is easier and less prone to mistakes than writing an interface. With an interface, you have to duplicate the procedure argument list. Then if you revise the procedure, you also have to revise the calls (of course!) but also the interface.

An explicit interface (interface statement or module) is required when you use “advanced” arguments. Otherwise the compiler doesn’t know to generate the correct call

If you have a procedure that is useed, you shouldn’t describe it with external. There are very few uses of external in modern Fortran — so, remove the external attributes, put all of your procedures into a module, and use them.

Leave a Comment