Procedures and modules

Subroutines and functions, the INTENT of a dummy argument, optional and keyword arguments, and the PURE and ELEMENTAL procedures a compiler can inline. Explicit interfaces and generic interfaces follow, then operator overloading, which makes a derived type behave like a number. The part ends on the module: what USE brings in, what a SUBMODULE keeps out of the interface, and how a procedure is passed as an argument.

6.1 Subroutines and functions SUBROUTINE and FUNCTION, CALL, the result variable, RETURN and a result that is a value Open 6.2 INTENT and the dummy argument rules INTENT(IN), INTENT(OUT), INTENT(INOUT), what each promises, and the error the compiler gives Open 6.3 OPTIONAL arguments and PRESENT an OPTIONAL dummy, PRESENT, a default when it is absent, and a call with keywords Open 6.4 Keyword arguments the dummy name in a call, the order that then does not matter, and a call that mixes both Open 6.5 PURE, ELEMENTAL and side effects a PURE function and what it may not do, ELEMENTAL over an array, and the automatic interface Open 6.6 Recursion a recursive FUNCTION, the RESULT clause, a base case, and the depth a stack allows Open 6.7 Interfaces and explicit interfaces an INTERFACE block, why a module gives it for free, EXTERNAL and the mismatch it hides Open 6.8 Generic interfaces INTERFACE with a generic name, several specific procedures, and a call resolved by the argument type Open 6.9 Operator overloading and ASSIGNMENT(=) INTERFACE OPERATOR(+), INTERFACE ASSIGNMENT(=), and a vector type with arithmetic Open 6.10 Modules, USE and ONLY MODULE, CONTAINS, USE and USE ... ONLY, renaming, and the .mod file gfortran writes Open 6.11 Submodules a module interface with a MODULE PROCEDURE, a SUBMODULE that implements it, and the build order Open 6.12 Procedures as arguments and procedure pointers a dummy procedure, an INTERFACE for it, a PROCEDURE POINTER and a table of functions Open

Lessons