Can't compile with module and main program in same file

前端 未结 1 765
梦毁少年i
梦毁少年i 2021-01-12 06:56

I am trying to make use of a module that is in the same file as my main program. However, I cannot get it to work. Does Fortran allow a module to be contained in the same fi

相关标签:
1条回答
  • 2021-01-12 07:23

    Yes, Fortran does allow modules to be contained in the same file as the main program. However, modules must be written before the main program:

    module my_module
      contains
        subroutine my_subroutine()
          print *, "Hello World!"
        end subroutine my_subroutine
    end module my_module
    
    program main
      use my_module
      call my_subroutine()
    end program main
    
    0 讨论(0)
提交回复
热议问题