15 October 2010

Fortran generic interface mixed with iso_c_binding

I'm going crazy trying to figure out some Fortran generic interface funkiness. The compiler's complaining that a function call doesn't match a generic interface despite the fact that only one module procedure statement is in the interface block and the same damned code compiles when I write the concrete procedure name instead of the generic name.

Just so I've got it later, this happens to work:

module testing

  use, intrinsic :: iso_c_binding, only: c_float, c_double
  private :: c_float, c_double

  interface test
    module procedure test1
    module procedure test2
  end interface


  real(c_float) function test1 (x)
    real(c_float), intent(in) :: x(*)
    test1 = 2 * x(1)
  end function test1

  real(c_double) function test2 (x)
    real(c_double), intent(in) :: x(*)
    test2 = 2 * x(1)
  end function test2

end module testing

program main
  use testing
  implicit none
  real(4) :: s(1)
  real(8) :: d(1)
  s = 2.0
  d = 2d0
  write (*,*) test(s)
  write (*,*) test(d)
end program main
This snippet, however, is not the thing that's breaking...

Subscribe Subscribe to The Return of Agent Zlerich