022. Functions should be pure and have intent(in) arguments#
topic: Procedures
intent(in) arguments cannot be changed.
pure = no side effects.
Use subroutine instead for a procedure with side effects.
func.f90 | |
|
#
#print *, area(3., 4.) ! 12
contains
real pure function area(length, width)
real, intent(in) :: length, width
area = length*width
end function area
end
real in the function definition line indicates the type of the return value.
By default, the value corresponding to a variable with the same name as the function
is returned (here area).
Demo of a Fortran function. Intent(in) arguments
— FortranTip (@fortrantip) December 19, 2021
cannot be changed. Function arguments should be intent(in). Pure = no side-effects.
print*,area(3.,4.) ! 12
contains
real pure function area(length,width)
real, intent(in) :: length,width
area = length*width
end function area
end
- 1
Compiled using
GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0with no flags