PURE attribute
Standard: F77 F90 F95 F2003 F2008 F2018 Example program
<Syntax>
PURE
The PURE keyword may appear only in the prefix of a FUNCTION or SUBROUTINE statement.
<Semantics>
The PURE keyword specifies that all procedures defined by this subprogram are “pure”; that is, they have no side effects. (A subprogram can define several procedures by using the ENTRY statement.) A pure procedure can thus be used safely in contexts where side-effects are problematic; that is, in specification expressions and in DO CONCURRENT and FORALL constructs.
A pure subprogram must obey the following rules:
- every nonpointer dummy argument must have an INTENT attribute, and for a pure function, that must be INTENT(IN);
- no local variable is permitted to have the SAVE attribute;
- it must not reference any VOLATILE variable;
- it must not assign a value to any non-local variable, except that a pure subroutine can assign a value to an INTENT(INOUT) or INTENT(OUT) dummy variable;
- it must not invoke a non-pure procedure;
- it must not contain any input/output statement, except for READ or WRITE of an internal file;
- it must not contain a STOP statement;
- it must not contain an image control statement;
- Fortran 2008 only: it must not contain an ERROR STOP statement (this restriction is removed in Fortran 2018).
The PURE attribute is also implied by the ELEMENTAL attribute, except when ELEMENTAL is accompanied by the IMPURE attribute.
<Related>
DO CONCURRENT construct, ELEMENTAL attribute, ENTRY statement, FORALL construct, FUNCTION statement, IMPURE attribute, SUBROUTINE statement