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

generic interface and dummy procedure arguments

pletzer
Beginner
439 Views
Hi,

It seems that it is not possible to create generic interfaces based on different dummy procedure signatures. This is illustrated by the following program, which, when compiled with ifort 9.0.027, will print the following error message:

fortcom: Error: b1.F90, line 22: The type/rank/keyword signature for this specific procedure matches another specific procedure that shares the same generic-name. [TEST2]
subroutine test2(s2)
-------------^
fortcom: Error: b1.F90, line 34: This module file was not generated by any release of this compiler. [TEST_MOD]
use test_mod
------^
compilation aborted for b1.F90 (code 1)

The two procedures test1 and test2 differ by the signature of their dummy procedure argument, which takes a subroutine with a real scalar in the first case, and a subroutine taking a raeal array in the second case.

Does anybody know what the Fortran standard says about this? Thanks for your help.

--Alex.


! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
module test_mod
implicit none
public :: test

interface test
module procedure test1
module procedure test2
end interface

contains

subroutine test1(s1)
interface
subroutine s1(x)
real, intent(in) :: x
end subroutine s1
end interface
call s1(1.0)
end subroutine test1

subroutine test2(s2)
interface
subroutine s2(x)
real, intent(in) :: x(:)
end subroutine s2
end interface
call s2((/1.0,2.0/))
end subroutine test2

end module test_mod
! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
program test_prog
use test_mod
implicit none

interface
subroutine t1(x)
real, intent(in) :: x
end subroutine t1
end interface
interface
subroutine t2(x)
real, intent(in) :: x(:)
end subroutine t2
end interface

call test(t1)

end program test_prog

subroutine t1(x)
real, intent(in) :: x
write(*,*) 't1:', x
end subroutine t1
subroutine t2(x)
real, intent(in) :: x(:)
write(*,*) 't2:', x
end subroutine t2
0 Kudos
1 Reply
Steven_L_Intel1
Employee
439 Views
Here is what the standard says (I'm quoting Fortran 2003 here):

28 Two dummy arguments are distinguishable if neither is a subroutine and neither is TKR compatible
29 (5.1.1.2) with the other.
...
2 Within a scoping unit, two procedures that have the same generic name shall both be subroutines or
3 both be functions, and
4 (1) there is a non-passed-object dummy data object in one or the other of them such that
5 (a) the number of dummy data objects in one that are nonoptional, are not passed-object,
6 and with which that dummy data object is TKR compatible, possibly including that
7 dummy data object itself,
8 exceeds
9 (b) the number of non-passed-object dummy data objects, both optional and nonoptional,
10 in the other that are not distinguishable with that dummy data object;
11 (2) both have passed-object dummy arguments and the passed-object dummy arguments are
12 distinguishable; or
13 (3) at least one of them shall have both
14 (a) A nonoptional non-passed-object dummy argument at an effective position such that
15 either the other procedure has no dummy argument at that effective position or the
16 dummy argument at that position is distinguishable with it; and
17 (b) A nonoptional non-passed-object dummy argument whose name is such that either
18 the other procedure has no dummy argument with that name or the dummy argument
19 with that name is distinguishable with it.
20 Further, the dummy argument that disambiguates by position shall either be the same as
21 or occur earlier in the argument list than the one that disambiguates by name.
22 The effective position of a dummy argument is its position in the argument list after any passed-object
23 dummy argument has been removed.


TKR means Type, Kind, Rank.

Note that dummy arguments that are subroutines are not "distinguishable". This means that the interface to the subroutine dummy argument itself is not a factor in generic resolution.
0 Kudos
Reply