This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Problem with generic interfaces.
- From: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>
- To: Gunnar Björkman <bjorkmang at gmail dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Wed, 3 Nov 2010 06:07:21 +0100
- Subject: Re: Problem with generic interfaces.
- References: <AANLkTikp8b9-K3Rp9dDyZ_a3BoeEd85hh2xp+Xt+6dLs@mail.gmail.com>
Dear Gunnar,
> I have started to get problems with my generic interfaces, with
> gfortran downloaded from
> ftp://ftp.equation.com/gcc/gcc-4.6-20101030-32.exe.
>
> I have come to the conclusion that the problem might be related to
> interfaces where I in the procedures have mixed a type and types
> extended from that type.
>
> My question is then, is the following code legal?
No, gfortran tells you:
gunnar.f90:9.37:
module procedure testa_a, testa_b
1
Error: Ambiguous interfaces 'testa_b' and 'testa_a' in generic
interface 'testa' at (1)
gunnar.f90:24.9:
use test
1
Fatal Error: Can't open module file 'test.mod' for reading at (1): No
such file or directory
ifort opines:
gunnar.f90(30): error #8032: Generic procedure reference has two or
more specific procedure with the same type/rank/keyword signature.
[TESTA]
call testa(b)
--------^
compilation aborted for gunnar.f90 (code 1)
>
> (I can solve my problem by using type instead of class for my
> declarations in the subroutines.)
>
Indeed. The ambiguity arises because instances of CLASS(a) can be of
CLASS(b). Which of test_a and test_b should chosen in this case?
Cheers
Paul
> module test
> ?type a_type
> ? ? integer :: a
> ?end type a_type
> ?type,extends(a_type):: ?b_type
> ? ? integer :: b
> ?end type b_type
> ?interface testa
> ? ? module procedure testa_a, testa_b
> ?end interface
> contains
> ?subroutine testa_a(a)
> ? ?class(a_type) :: a
> ? ?a%a =1
> ?end subroutine testa_a
> ?subroutine testa_b(b)
> ? ?class(b_type) :: b
> ? ?b%a =1
> ? ?b%b =1
> ?end subroutine testa_b
> end module test
>
> module aa
> ?use test
> contains
> ?subroutine aaa(a,b)
> ? ?type(a_type) :: a
> ? ?type(b_type) :: b
> ? ?call testa(a)
> ? ?call testa(b)
> ?end subroutine aaa
> end module aa
>
> Regards,
>
> Gunnar
>