http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51268

--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-11-23 
10:22:12 UTC ---
(In reply to comment #2)
> Well, we are definitely interested in what the standard says exactly.

For links to the standards see:
  http://gcc.gnu.org/wiki/GFortranStandards

I think the following of "11.2.2 The USE statement and use association" of
Fortran 2008 should capture this:

"Two or more accessible entities, other than generic interfaces or defined
operators, may have the same local identifier only if the identifier is not
used. Generic interfaces and defined operators are handled as described in
12.4.3.4. Except for these cases, the local identifier of any entity given
accessibility by a USE statement shall differ from the local identifiers of all
other entities accessible to the scoping unit."


> Because if this is explicitly forbidden, we are wondering what the Fortran
> committee had in mind for programs using thousands of subroutines and where
> the programmers want to provide the interfaces for each.

I think your idea is to "hide" the implementation (the subroutines) from the
interfaces (i.e. the module itself).

Well, until Fortran 2003, they had no real solution but then they created the
Technical Report (TR) 19767:2005 "Enhanced Module Facilities". This TR is now
part of Fortran 2008 and informally known as "submodules":

There is only one important downside: So far, almost no compiler supports
submodules; http://fortranwiki.org/fortran/show/Fortran+2008+status lists only
Cray.

With submodules you can create a master module:

module master
  interface
    MODULE SUBROUTINE sub (a,b)
      integer, intent(in) a, b
    end subroutine
  end interface
end module master

SUBMODULE (master) implementation
contains
  MODULE SUBROUTINE sub (a,b)
    integer, intent(in) a, b
    ! < implementation >
  end subroutine
end module implementation

Variant which saves typing by leaving out the repeated variable declaration:

SUBMODULE (master) implementation
contains
  MODULE SUBROUTINE sub
    ! < implementation >
  end subroutine
end module implementation

 * * *

(In reply to comment #2)
> I just hope the official recommendation is different from defining all
> the subroutines as module procedures in a single 100000-lines long module...

Well, you could use multiple modules for the actual implementation and then
collect all of them in

  module master
    use m1
    use m2
    ...
  end module master

This will automatically export all (public) procedures from the used modules
such that
  "use master"
will work.

This is not as flexible as submodules but it valid and works since Fortran 90.

Reply via email to