- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do 2 pointers to 2 functions require 2 interfaces?
Do 3 pointers to3 functions require3 interfaces?
and so on
The question relates to CVF 6.6 and arises from the use of LoadLibrary and GetProcAddress to call functions from a DLL.
However, I think my question concerns the language.
If I have 2 functions with the same 'signature' (return type, argument types) and I want 2 function pointers pointing to each one, ...
... Do I have to repeat the interface defintion?
See the attached source file for more info.
The necessity to repeat the interfaces is a minor irritation where there are only 2 or 3 of them. But it's more of a pain when the numbers grow or are even unknown at the time of compilation.
I think that I want a function type associated with a particular function signature. I can then declare several pointers pointing to functions of the same type. (You may guess that I come from a C++ background.)
Is there any way in FORTRAN of doing something similar?
I can see that one solution is to maintain just one function pointer and one interface and call GetProcAddress whenever necessary. But this will have some performance cost.
A development of that may be to keep the results of GetProcAddress in an integer array and assign the relevant element to the function pointer each time.
Any comments?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dmw@hrwallingford.co.uk:Do 2 pointers to 2 functions require 2 interfaces?
Do 3 pointers to3 functions require3 interfaces?
I think that I want a function type associated with a particular function signature. I can then declare several pointers pointing to functions of the same type. (You may guess that I come from a C++ background.)
...but no, you don't have to have 2 interfaces to 2 functions, as long as they have the "same" signature. One will suffice, and the interface will kind of denote a "signature". IOW, you may write (untested):
INTERFACE
SUBROUTINE S1(x,y,z)
integer:: x
real:: y,z
END SUBROUTINE
END INTERFACE
POINTER(P1, S1)
POINTER(P2, S1)
But, due to the "dual" nature of Cray pointer, you must take care to switch the pointers accordingly each time, i.e.
P1 = GetProcAddress(..."Func1")
CALL S1(a,b,c)
P2 = GetProcAddress(..."Func2")
CALL S1(a,b,c)
which kind of defeats the purpose . But you may store the pointers P1... P2 in an array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your answer which helps to clarify my mind.
I didn't really want different names for my functions. I wanted different pointers to the same function interface and to invoke the function via its pointer.
But I'll accept that FORTRAN doesn't do it that way
Thank you for the advice re INT_PTR_KIND.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your answer which points to the solution towards which I was approaching.
I needed the assurance of 2 experts, such as Steve and yourself, that there was no other language feature which I was missing.
See also my reply to Steve.
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can't have two POINTER statements for the same function/interface name.
t.f90(8) : Error: Multiple declaration of a pointee. [S1]
POINTER(P2, S1)
------------^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Of course, multiple different functions still can be called through a single (pointer, pointee) interface, provided that the pointer is reassigned appropriately before each instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Something like that
INTERFACE
SUBROUTINE S1(x,y,z)
integer:: x
real:: y,z
END SUBROUTINE
END INTERFACE
POINTER(PTR_S1, S1)
INTEGER*4 PTR(:)
PTR(1) = GetProcAddress(..."Func1")
PTR(2) = GetProcAddress(..."Func2")...
PTR_S1=PTR(1)
CALL S1(a,b,c)
PTR_S1=PTR(2)
CALL S1(a,b,c)
...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page