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

Pointer Array possible?

ferrad01
Beginner
468 Views
I have set up a bunch of pointers (from p_PROC01 to p_PROC41) defined in a module which hold the address of 41 functions in a 3rd party DLL, using:

interface
subroutine DMS_GETOLIPATH_F(PTH,IER)
implicit none
character(*) :: PTH
integer :: IER
end subroutine DMS_GETOLIPATH_F
end interface

POINTER ( p_PROC01, DMS_GETOLIPATH_F )

etc for all 41 entry points.

Then I do a GetProcAddress of each manually:

p_PROC01 = GetProcAddress (dll_handle, PROCS(1)//char(0)); if (p_PROC01 == NULL) ierr = 01
p_PROC02 = GetProcAddress (dll_handle, PROCS(2)//char(0)); if (p_PROC02 == NULL) ierr = 02
p_PROC03 = GetProcAddress (dll_handle, PROCS(3)//char(0)); if (p_PROC03 == NULL) ierr = 03
...
etc, 41 lines for all 41 functions

My questions is can I get these pointers into an array so I would only need one statement such as:

do j = 1, 41
p_PROC(j) = GetProcAddress (dll_handle, PROCS(j)//char(0)); if (p_PROC(j) == NULL) ierr = j
enddo

If so, can someone help with the syntax?
0 Kudos
1 Reply
Steven_L_Intel1
Employee
468 Views
In Fortran, the way you have to do this is an array of derived type with a pointer component. You cannot have an array of pointers, directly.

I suggest you also look at features such as procedure pointers and the C interoperability features related to procedure pointers, such as type C_FUNPTR and procedure C_F_PROCPTR. The way I might approach what you're doing is an array of derived type containing a component of type C_FUNPTR. In the loop, I'd get the address of each entry and do a TRANSFER to convert the return from GetProcAddress to a type C_FUNPTR and store that in the array. Then when I wanted to call a routine, I'd declare a local procedure pointer with the correct abstract interface for the routine and call C_F_PROCPTR to convert the C_FUNPTR to a procedure pointer, then call the procedure.
0 Kudos
Reply