Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor II
8 Views

Scope of IMPLICIT statement in SUBMODULES

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
Valued Contributor III
8 Views

This was discussed in a

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

0 Kudos
Highlighted
Valued Contributor III
8 Views

Maybe it was this thread....

0 Kudos
Highlighted
Black Belt Retired Employee
8 Views

The standard says "An

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.

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos
Highlighted
New Contributor II
8 Views

Yes I can see a submodule

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.

0 Kudos
Highlighted
Valued Contributor III
8 Views

Quote:Andrew Smith wrote:

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.

0 Kudos
Highlighted
Black Belt Retired Employee
8 Views

You could consider that a

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. 

--
Steve (aka "Doctor Fortran") - https://stevelionel.com/drfortran
0 Kudos