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
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!!?
@FortranFan , I'm puzzled by your comment. The numbered syntax rules for an interface block do not allow for an executable statement. See 126.96.36.199 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.
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.