- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is no purpose - it's not allowed by the language. That ifort doesn't complain is a bug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve. That did sound quite fishy indeed!
@Barbara_P_Intel , here is a bug for you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What would I do without you guys?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!!?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I now see error messages for both ifx and ifort in the compilers that were released this week as part of oneAPI HPC Toolkit 2023.2.
Please check out this new release.
$ ifx --version
ifx (IFX) 2023.2.0 20230622
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.
$ ifx -c interface.f90
interface.f90(7): error #6622: This statement is invalid in an INTERFACE block.
WRITE(*, *) 2*X
----^
compilation aborted for interface.f90 (code 1)
$ ifort --version
ifort (IFORT) 2021.10.0 20230609
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.
$ ifort -c interface.f90
interface.f90(7): error #6622: This statement is invalid in an INTERFACE block.
WRITE(*, *) 2*X
----^
compilation aborted for interface.f90 (code 1)
$
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page