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

Bug with extraneous declarations in interface block.

OP1
New Contributor III
524 Views

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 Replies
mecej4
Honored Contributor III
513 Views

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
Honored Contributor III
475 Views

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.

0 Kudos
OP1
New Contributor III
468 Views

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).

0 Kudos
andrew_4619
Honored Contributor III
464 Views

"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? 

0 Kudos
OP1
New Contributor III
405 Views

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.

0 Kudos
Steve_Lionel
Honored Contributor III
458 Views

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

0 Kudos
Reply