About 'use' statement usage

Angelo Graziosi angelo.g0@libero.it
Thu Sep 6 16:01:00 GMT 2018


Often a module calls 'elements' (variables, functions, subroutines etc.) from other modules. The 'called' module can be 'used' once, at the beginning of the 'calling' module or repeated for each function/subroutine 'using' it. In short,

CASE 1
======

module foo
  use bar, only: bar0, bar1, bar2,...

  ! using bar0
  ... bar0 ...

contains

  subroutine sub_bar1()
    ...
    ... bar1 ...
  end sub...

  subroutine sub_bar2()
    ...
    ... bar2 ...
  end sub...

  ...
end module foo


CASE 2
======

module foo
  use bar, only: bar0

  ! using bar0
  ... bar0 ...

contains

  subroutine sub_bar1()
  use bar, only: bar1
    ...
    ... bar1 ...
  end sub...

  subroutine sub_bar2()
  use bar, only: bar2
    ...
    ... bar2 ...
  end sub...

  ...
end module foo


Which is better? CASE1 or CASE 2?

TIA.

Ciao,
 Angelo.



More information about the Fortran mailing list