Question

When I try to compile code under the statement with ifort it returns error as:

    error #8169: The specified interface is not declare

But it works perfectly on gfortran, for some reason I have to use intel compiler to compile this work. The language I am using is Fortran. The reason for this is that the 'ifort' compiler does not see the variables in Interface. So I develop a module called Var to do fix that. And Use it in every blocks. But it returns error:

This USE statement is not positioned correctly within the scoping unit.

The var module is like following:

MODULE VAR
      CHARACTER(50) :: callbackID
END MODULE

how can I fix the problem thanks alot! My compiler version is ifort 12.1.0

      MODULE DEMO
      USE VAR
      INTERFACE
        SUBROUTINE callback_prototype(callbackID)
            USE VAR
            CHARACTER(*) :: callbackID
        END SUBROUTINE callback_prototype
      END INTERFACE

      PROCEDURE( callback_prototype ), POINTER :: f_ptr => NULL()

      CONTAINS
      SUBROUTINE set_callback(func)
         IMPLICIT NONE
         EXTERNAL :: func

          f_ptr => func
          call HELLO
      END SUBROUTINE

      SUBROUTINE invoke_callback(callbackID)
          CHARACTER(*) :: callbackID
          if (associated(f_ptr)) call f_ptr(callbackID)
      END SUBROUTINE

      SUBROUTINE HELLO

      IMPLICIT NONE

      !dosomthing


      END SUBROUTINE
      END MODULE
Was it helpful?

Solution

The code as presented is not legal fortran. The use statement inside the interface body makes accessible a name that is the same as a dummy argument. This violates the scoping rules of the language.

The use statement inside the interface body would appear to be superfluous.

OTHER TIPS

I don't see the reason why you want the use statement in the interface in the first place. Even the interface can be skipped, because you have the right procedure accessible:

PROCEDURE( invoke_callback ), POINTER :: f_ptr => NULL()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top