024. Put functions and subroutines in modules to ensure that interfaces are checked#

topic: Procedures

Fortran procedures should be defined in modules to ensure that interfaces are checked.

mod.f90 | | Godbolt Compiler Explorer logo | Fortran logo#
module m

contains

integer function area(length, width)
   integer, intent(in) :: length, width
   area = length*width
end

end module m

program main
  use m
  
  print*,area(3,4) ! 12

end program main
Output1#
          12


1

Compiled using GNU Fortran (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 with no flags