genericsfortranintel-fortranfortran2003

having generic internal procedure with ifort compiler


The following works with gfortran or f95, but not with ifort:

  interface add
     procedure addr, addi
  end interface add

  real a, b
  integer i, j

  data a, b, i, j /1.0, 2.0, 1, 2/


  call add(a,b)
  call add(i,j)

  stop
  contains 

  subroutine addr(x,y)
  real x, y
  print *, x+y
  return
  end subroutine addr

  subroutine addi(m, n)
  integer m, n
  print *, m+n
  return
  end subroutine addi

  end

ifort returns this error:

  error #6643: This statement is incorrectly positioned.
            procedure addr, addi
   ---------^
  error #8168: Parentheses are required after the PROCEDURE keyword.
            procedure addr, addi
  ---------^

Assume that any module procedure can not be used (we don't want to have addr and addi in a module) and ifort has to be used as a compiler. Any help would be appreciated.


Solution

  • Intel Fortran 12.1.5 does not support the form or meaning of a procedure-stmt (the statement inside the interface block that the error refers to) without the leading MODULE keyword.

    (Consequently the compiler has classified the line as a procedure-declaration-stmt - hence the two errors.)

    The form of the procedure statement without the leading module was introduced in the Fortran 2003 standard, the ability to have internal procedures as specific procedures behind a generic interface was introduced in the Fortran 2008 standard.

    There is no work around, given your stated requirement of not being able to use module procedures, until Intel Fortran supports that particular Fortran 2008 feature.