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

COMPILER BUG or standard behavior? generic interface for intrinsic procedures

Valued Contributor I

The following code compiles and runs fine with gfortran, which is an absolutely nice and desired behavior to have for generic programming.

program size_len_interface
    intrinsic :: len
    interface size
        procedure :: len
    end interface
    print *, size("string")
    print *, size([1, 2, 3])
end program size_len_interface

The Intel ifort classic 2021.2 however, yields various kinds of error messages like,

size_len_interface.f90(3): error #6409: This name has already been used as an external procedure name.   [LEN]
        procedure :: len

I sincerely hope this is a bug in ifort and not a current Fortran standard limitation. Generic interfaces for intrinsic procedures are essential to avoid ugly preprocessing directives in generic procedures that work with multiple types.



0 Kudos
1 Reply
Honored Contributor III

@DataScientist ,

What you show does not conform to the Fortran standard per my understanding.  The "procedure" statement on line 4 of your code is for external procedures or those defined by means other than Fortran and not intrinsic procedures, from what I understand.

The standard does support the following wrapper approach in case that interests you?


module m
   interface size
      module procedure :: get_len
   end interface
   elemental function get_len( s ) result(r)
      character(len=*), intent(in) :: s
      integer :: r
      intrinsic :: len
      r = len( s )
   end function
end module 
   use m, only : size
   print *, size("string")
   print *, size([1, 2, 3])


Separately the support for Generics in Fortran has considerable gaps and there is a plan to address them in Fortran 202Y standard revision with compiler support expected in 203X period.  But you will have to work within Fortran's limitations for a while.