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

wrong code but no compiler warning

kay-diederichs
New Contributor I
315 Views

Today I was surprised that gfortran diagnoses a simple error but neither ifort nor ifx do.

Consider the following code:

      REAL a1,a2

      CALL sub1(a1)

      CALL sub1(a1,a2)

      END

      SUBROUTINE sub1(a)

      REAL a

      END

Here, the first call to sub1 employs 1 argument, the second employs 2. I was expecting the compiler to throw an error. GFORTRAN does:

    3 |       CALL sub1(a1,a2)

       |                      1

Error: More actual than formal arguments in procedure call at (1)

 

but ifort version 2021.12.0 and ifx version 2024.1.0 don't flag this. Tried the -stand and -check options but that doesn't change anything.

What am I overlooking?

Thanks, Kay

0 Kudos
1 Solution
andrew_4619
Honored Contributor II
286 Views

You are assuming that the main program knows about the interface to sub1 but sub1 is external there is no interface provided either by having sub1 in a module or having an explicit interface given in the main program. a2 could in fact be defined as an optional argument in sub1.  If you compile that with interface checking switched on (/warn:interfaces)  you should get a warning/error

View solution in original post

3 Replies
andrew_4619
Honored Contributor II
287 Views

You are assuming that the main program knows about the interface to sub1 but sub1 is external there is no interface provided either by having sub1 in a module or having an explicit interface given in the main program. a2 could in fact be defined as an optional argument in sub1.  If you compile that with interface checking switched on (/warn:interfaces)  you should get a warning/error

Steve_Lionel
Honored Contributor III
286 Views

You should have tried -warn.

D:\Projects>ifx -warn:interface t.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

t.f90(5): error #6784: The number of actual arguments cannot be greater than the number of dummy arguments.   [SUB1]
      CALL sub1(a1,a2)
-----------^
compilation aborted for t.f90 (code 1)
kay-diederichs
New Contributor I
276 Views

Hi Andrew and Steve,

thanks for pointing this out! I thought -warn is the default but I was wrong. Will remember this!

Best wishes,

Kay

0 Kudos
Reply