Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26750 Discussions

Scope of IMPLICIT statement in SUBMODULES

Andrew_Smith
New Contributor III
110 Views

An earlier thread concluded that IMPLICIT (NONE) in a module applied to all procedures defined in the scoping unit of the module.

Now we have SUBMODULES we need to consider the scope of IMPLICIT again. SUBMODULES inherit the scope of the parent module, i.e. they see all the type definitions, variable declarations and the procedures and more I expect. So until now I was assumming they have visibility the IMPLICIT statements too. But by accident I discovered they don't. This seams an odd choice to me and something worthy of making a note of in the help file.

module A
   implicit none
   
contains
   subroutine bar()
      x = 1
   end
end module

submodule(A) B

contains
   subroutine foo()
      y = 1
   end
end

Intel Fortran complains correctly about X = 1, but ignores Y = 1, giving Y a default real type.

0 Kudos
6 Replies
andrew_4619
Honored Contributor I
110 Views

This was discussed in a thread in the last year but I just had a quick search and haven't found it..... 

andrew_4619
Honored Contributor I
110 Views
Steve_Lionel
Black Belt Retired Employee
110 Views

The standard says "An IMPLICIT NONE statement can indicate that no implicit typing rules are to apply in a particular scoping unit..." The term "scoping unit" has a precise definition. It is easy to assume that because a submodule can "see" declarations in its parent module that an IMPLICIT is also inherited, but that's not the case. A submodule is its own scoping unit, not part of the parent module.

Andrew_Smith
New Contributor III
110 Views

Yes I can see a submodule needs its own scoping unit. However I don't see why it does not inherit/copy the IMPLICIT definition like it does everything else from the parent module scope.

I dont have a copy of F2008 but I found these key statements in the IBM documentation:

"A submodule is a program unit that extends a module or another submodule."

and:

"A submodule has access to the entities that are declared and defined in its ancestor module or submodules by host association"

Maybe IMPLICIT just got forgotten but a sensible interpretation would be that IMPLICIT statements should carry over to the SUBMODULES scope. Then the module procedures see the same environment as the module procedure interfaces.

FortranFan
Honored Contributor II
110 Views

Andrew Smith wrote:

..  dont have a copy of F2008 but I found these key statements in the IBM documentation: ..

The standard effectively ties the IMPLICIT statement to a scoping unit and it indicates the SUBMODULE is a separate unit from the MODULE.  SUBMODULE has access to data entities from its ancestors via host association which is a different concept per the standard.

Steve_Lionel
Black Belt Retired Employee
110 Views

You could consider that a module that USEs another module "extends" the first, but it is its own scoping unit and doesn't pick up an IMPLICIT from the module(s) it USEs. 

Reply