Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Diskussionen

Bug with extraneous declarations in interface block.

OP1
Neuer Beitragender III
1.054Aufrufe

The following code does compile, but shouldn't the compiler warn about the completely useless declaration statement for I inside the interface block?

This is with IFX 2024.1.0 (and same with the latest IFORT version).

MODULE M
IMPLICIT NONE (TYPE, EXTERNAL)
INTERFACE
    MODULE SUBROUTINE S
    IMPLICIT NONE (TYPE, EXTERNAL)
    INTEGER :: I
    END SUBROUTINE S
END INTERFACE
END MODULE M
0 Kudos
6 Antworten
mecej4
Geehrter Beitragender III
1.043Aufrufe

It will, if you request warnings; its doing so when warnings are not requested could be unpleasant or inconvenient.

 

S:\LANG>ifx /warn /c dontnag.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.2.0 Build 20240602
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

dontnag.f90(6): remark #7712: This variable has not been used.   [I]
    INTEGER :: I
---------------^
Steve_Lionel
Geehrter Beitragender III
1.005Aufrufe

The standard permits most anything that can be in a specification section inside an interface body; exceptions include FORMAT and DATA. Ideally, you should not be writing interface blocks for Fortran procedures - put them in modules or in a CONTAINS section instead.

OP1
Neuer Beitragender III
998Aufrufe

Steve - our best practice is to declare interfaces (for all our procedures) in modules (or submodules); and have the body of those procedures CONTAINed in submodules of those modules (or submodules).

andrew_4619
Geehrter Beitragender III
994Aufrufe

"Ideally, you should not be writing interface blocks for Fortran procedures". I am not sure I can get behind that.  Old style F77 external routines is much more prone to errors and plain modules in larger applications leads to horrendous build cascades so we are forced into submodules and to write lots of interfaces for the exposed module procedures. What other choice is there? 

OP1
Neuer Beitragender III
935Aufrufe

Yes, submodules are one of the best things that have happened to Fortran since F2008! They bring so much clarity to our code structures, and they help avoid that dreaded compilation cascade problem! And of course you need to declared interfaces for the module procedures contained in those submodules - a very small price to pay given the overall benefits.

Steve_Lionel
Geehrter Beitragender III
988Aufrufe

I did say "ideally", and there are of course challenges when trying to modernize old code. 

Antworten