- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
InFortran, we can use functions as arguments of procedures. However, while doing that we supply the names of the functions by ourselves. Assume that I have two characters myF1 and myF2 with values 'F1' and 'F2', respectively.
If a had an external function named as F1, then
some_other_function(F1)
might work but what if I want something like
some_other_function(myF1)
where the name is a character, this would give a run-time error. But my point is, I want to decide on the argument depending on the computed values comes from somewhere else on the program. If I calculate 3 let's say, then I want to call F3, if 5 then F5. This is just to generalization of an existing code. Of course one can always add select case statements of define function names upto F99 for instance.
This might look unnecessary but it is extremely useful. In Matlab forinstance, something similar can be perfomed. I wonder if such an operation is possible with Intel Fortran or maybe with Fortran 2003 extensions.
Erhan
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try something like this (it works on dlls where function given by myF1 must be declared as DLLEXPORT, but I do not know if it will work on procedure which is in your exe file as I suppose it is).
pProc=GetProcAddress("ourExe.exe"C,trim(myF1)//""C)
some_other_function(pProc)
recursive subroutine some_other_function(sub)
external sub
call sub()
end subroutine
I hope it helps
Jakub
pProc=GetProcAddress("ourExe.exe"C,trim(myF1)//""C)
some_other_function(pProc)
recursive subroutine some_other_function(sub)
external sub
call sub()
end subroutine
I hope it helps
Jakub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply but this might not help. I said external functions but they are actually not external, functions are defined in the code indeed. Since I'm also using linux as well, I need something portable.
By the way, all of my functions are in a module so they are accessible with "use module" instead of defining them as
real, external - one by one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Erhan,
Create an array of function addresses
some_other_function(myF(1))
Jim Dempsey
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you are concerned about possible argument errors in release mode then make myF(n) a function that returns the function address (or reference to the address), and performs sanity check in the process.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page