Fortran

Guide To Learn

A Fortran procedure is pure when it doesn’t cause any observable side effects, such as I/O or modifying the value of a variable declared outside of the procedure. To define a procedure as pure, simply add the pure attribute to its function or subroutine statement, as shown in the following listing.

Listing 3.17 Defining a pure, side effect-free function

pure integer function sum(a, b)      ❶
  integer, intent(in) :: a, b
  sum = a + b
end function sum

❶ The pure attribute asserts that the function is free of side effects.

You can call a pure function in the same way as any other function, and ditto for subroutines.

What is a pure procedure?

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top