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

Cray pointer and functions

wkramer
Beginner
1,821 Views
Hello,

I use the procedure described in sample LoadExp1 to load subroutines from a DLL. This method fails when trying to load functions from a DLL.
The compiler starts complaining about the return value of the function not having a type, and that it must have an explicit type (although an interface is available).

The problem is related to the fact that there also exists a Cray-pointer which is intended to hold the function address.
Is this is caused by some kind of mix-up between function address and function return value?
I know that the pointee of the Cray-pointer cannot be a function result, but it is not at the pointer declaration where the compiler starts complaining, but at the point where I try to get the return value of the function.

How can I work around this problem?

Thanks,

Walter Kramer
0 Kudos
3 Replies
james1
Beginner
1,821 Views
Haven't had any problem of this sort, do you have a small example?

James
0 Kudos
wkramer
Beginner
1,821 Views
The cause of the problem was something completely different then I expected. It had to do with the placement of a use statement:

Module mod_A
  Interface
    real(4) function Func_A(a)
      real(4), intent(in) :: a
    end function Func_A
  End Interface
End Module mod_A

module mod_B
  use mod_A
contains
  real(4) function Func_B(lib,a)
    use kernel32
!    use mod_A
    implicit none
    character(*), intent(in) :: Lib
    real(4), intent(in) :: a
    pointer(q,Func_A)
    integer(4) :: p
    p=LoadLibrary(trim(Lib)//char(0))
    q = getprocaddress(p, "Func_A"C)
    Func_B=Func_A(a)
  end function Func_B
end module mod_B


The code as shown above generates the error.
If I move the
use mod_A
statement from module level to function level everything functions OK.
I hadn't expected this, but it solves my problem.
There is a relation with the pointer assignment though, because the following code will compile without any complaint:

Module mod_A
  Interface
    real(4) function Func_A(a)
      real(4), intent(in) :: a
    end function Func_A
  End Interface
End Module mod_A

module mod_B
use mod_A
contains
  real(4) function Func_B(a)
    implicit none
    real(4), intent(in) :: a
    Func_B=Func_A(a)
  end function Func_B
end module mod_B




Thanks,

Walter Kramer
0 Kudos
Steven_L_Intel1
Employee
1,821 Views
I think the error message for your original code is a bug. We'll look into it.

Steve
0 Kudos
Reply