Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
The Intel sign-in experience is changing in February to support enhanced security controls. If you sign in, click here for more information.
27551 Discussions

Why are executable statements allowed in interface blocks?

OP1
New Contributor II
293 Views

I realized by accident today that it is possible to have executable statements in an interface block. What is the purpose of this?

The code below compiles fine with the 2021.7.0 ifort compiler. It cannot be run (understandably) since the procedure S is not provided. Still, the presence of the WRITE statement in the interface block feels so strange.

I have probably written tens of thousands of interface blocks for module procedures (the introduction of submodules in fortran was truly the best thing since sliced bread) and never realized this quirk's existence.

 

MODULE M
IMPLICIT NONE (TYPE, EXTERNAL)
INTERFACE
    SUBROUTINE S(X)
    IMPLICIT NONE (TYPE, EXTERNAL)
    INTEGER :: X
    WRITE(*, *) 2*X
    END SUBROUTINE S
END INTERFACE
END MODULE M

PROGRAM P
USE M
IMPLICIT NONE
CALL S(1)
END PROGRAM P

 

0 Kudos
6 Replies
Steve_Lionel
Black Belt Retired Employee
287 Views

There is no purpose - it's not allowed by the language. That ifort doesn't complain is a bug.

OP1
New Contributor II
280 Views

Thanks Steve. That did sound quite fishy indeed!

@Barbara_P_Intel , here is a bug for you   ... and I also checked that both ifort and ifx exhibit this behavior.

Barbara_P_Intel
Moderator
269 Views

What would I do without you guys? I filed a bug, CMPLRLLVM-42318. I'll let you know when I know it's fixed.



FortranFan
Honored Contributor II
252 Views

Hi @Barbara_P_Intel ,

Can we have a quick chat here about this issue but in terms of the support incident you filed, can we pretend this discussion never happened!!?  Meaning, let your submission CMPLRLLVM-42318 remain as a bug report!!?

This is because the language standard for Fortran does not indicate a numbered constraint prohibiting an execution-part in an INTERFACE body and thus a processor is not compelled to include the capability to diagnose and report the presence of the offending part.  This may incline someone amongst the Intel Fortran to see this as a feature request instead!

However it is nice that Intel Fortran does report compile-time errors with certain executable statements in an interface body even though for some odd reason the WRITE statement flies under the radar c.f. line C in the snippet below versus A or B.

 

   interface
      subroutine sub()
         i = 1         !<-- A: error #6622
         !print *, i   !<-- B: error #6622
         !write(*,*) i !<-- C: no error
      end subroutine
   end interface
end 
C:\temp>ifx /c /standard-semantics p.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2022.2.0 Build 20220730
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

p.f90(3): error #6622: This statement is invalid in an INTERFACE block.
         i = 1        !<-- A
---------^
compilation aborted for p.f90 (code 1)

C:\temp>

 

You can then try to answer, is it a feature or bug!!?

Steve_Lionel
Black Belt Retired Employee
228 Views

@FortranFan , I'm puzzled by your comment. The numbered syntax rules for an interface block do not allow for an executable statement. See 15.4.3.2 in F2018. The compiler is required to be able to diagnose code that doesn't conform, and in the absence of a deliberate extension, it should here.

JohnNichols
Valued Contributor II
198 Views

Every time I see my Doctor, I am given a lecture on do not eat sliced bread.  Yesterday was a further example. 

The latest iteration of Intel ARC popped up today and said -- I am lonely you do not have any games.  

Fortran is simple, the stuff around it is hard. 

 

Reply