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!
26736 Discussions

scope of implicit none in interface block?

abhimodak
New Contributor I
175 Views

Hi

Is an interface block in a module supposed to honor the implicit none declaration in the module? I find that the "contained" procedures do so (as expected) but not the declarations in the interface block. Is this as per the standard?

A test program is below. (---which has j vs k usage which is kind of obvious but I encountered it in something like iFrom vs iForm. I agree that typically the interface blocks like this are "copied" from other files and /or auto generated; so such errors won't be that common, nevertheless.)

Abhi

---

      Module OM
   
         Implicit None
         
         Interface
            Subroutine Method(i, j)
               !Implicit None ! without this statement there is no compile-time error for "j"
               Integer :: i, k
            End Subroutine Method            
         End Interface
         
      Contains
      
         Subroutine Tech(i, j)
            Integer :: i, k ! the error for j vs k is caught
            i = 1
         End Subroutine Tech
         
      End Module OM

0 Kudos
5 Replies
Andreas_Z_
Novice
175 Views

Hi Abhi,

I would say that the observed behaviour makes sense. The interface block in the module provides information about the interface of the subroutine Method(i, j) in this case, which itself is a subroutine outside of the module (right?). So, that subroutine would also not be affected by the implicit none statement inside the module. Everything in between interface ... end interface should not depend on the settings in the module the interface is stated.

Andi

mecej4
Black Belt
175 Views

Abhi, you may find it useful to read about the IMPORT statement, see https://software.intel.com/en-us/fortran-compiler-18.0-developer-guide-and-reference-import .

Steve_Lionel
Black Belt Retired Employee
175 Views

No, IMPLICIT NONE does not propagate into the INTERFACE block. The way to view INTERFACE is as a window into the external procedure. Nothing from the enclosing scope is imported unless IMPORT is used.

FortranFan
Honored Contributor II
175 Views

An interface body is its own scoping unit, separate from that of a module or a program unit where it might be present.

abhimodak
New Contributor I
175 Views

Thank you for the responses. 

I do use "import"; it won't change the current behavior i.e. won't make implicit none "visible/applicable" in the scope of the Interface Block. I doubt if there is any (standard) way to get implicit none applied to all methods in the interface block. And that's all right considering the typical usage as mentioned in the original post.

Abhi

p.s. for those who may come to this thread anew, here is a link to somewhat much broader discussion (that I didn't find/read earlier): https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/783797

Reply