Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Avisos
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29286 Discusiones

Scope of IMPLICIT statement in SUBMODULES

Andrew_Smith
Colaborador Valioso I
1.589 Vistas

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 Respuestas
andrew_4619
Colaborador Distinguido III
1.589 Vistas

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

andrew_4619
Colaborador Distinguido III
1.589 Vistas
Steve_Lionel
Colaborador Distinguido III
1.589 Vistas

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
Colaborador Valioso I
1.589 Vistas

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
Colaborador Distinguido III
1.589 Vistas

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
Colaborador Distinguido III
1.589 Vistas

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. 

Responder