fortrangeneric-interface

Ambiguous interface in Fortran generic interface


I'm not familiar with Fortran. And here is a generic interface with some subroutines. gfortran 4.8 complains that:

Ambiguous interfaces 'sortic4' and 'sortic' in generic interface 'sorti' at (1)

        INTERFACE SORTI

            SUBROUTINE  SORTIC( N, IND, TBLC )
            INTEGER      , INTENT(IN   ) :: N
            INTEGER      , INTENT(INOUT) :: IND( N )
            CHARACTER*(*), INTENT(IN   ) :: TBLC( * )
            END SUBROUTINE  SORTIC

            SUBROUTINE  SORTIC4( N, IND, TBLC )
            INTEGER      , INTENT(IN   ) :: N
            INTEGER      , INTENT(INOUT) :: IND( N )
            CHARACTER*(*), INTENT(IN   ) :: TBLC( * )
            END SUBROUTINE  SORTIC4

            SUBROUTINE  SORTIC8( N, IND, TBLC )
            INTEGER(8)   , INTENT(IN   ) :: N
            INTEGER(8)   , INTENT(INOUT) :: IND( N )
            CHARACTER*(*), INTENT(IN   ) :: TBLC( * )
            END SUBROUTINE  SORTIC8

            SUBROUTINE  SORTI1( N, IND, TBL1 )
            INTEGER, INTENT(IN   ) :: N
            INTEGER, INTENT(INOUT) :: IND( N )
            INTEGER, INTENT(IN   ) :: TBL1( * )
            END SUBROUTINE  SORTI1
             ....
        END INTERFACE

The code comes from the ioapi3.1 library, m3utilio.f: http://www.baronams.com/products/ioapi/index.html

What is wrong?


Solution

  • You first two subroutines (SORTIC and SORTIC4) have exactly the same types, kinds and dimensions (ranks) of dummy arguments. The TKR resolution thus cannot difference between them, they are ambiguous. They must differ in some of these attributes to be usable in generic interface.

    The second and the third one differ in their kinds, this is OK. (Default integer and integer(8), kind 8 is not portable, but is most often distinct from the default one.) The first and the second one are the same.

    I looked in the source code of the library. I conclude, that this generic interface does not conform to the Fortran 90 and later standards. Therefore I would start with changing it to a regular interface block just for the explicit interface, i.e., delete the name SORTI after the word interface, and call the individual subroutines directly.