Calling a subroutine whose name is in a variable

Calling a subroutine whose name is in a variable

Is it possible to call a subroutine whose name is in a variable?
Let's say for example I have a character array with the string 'MYFUNCTION' in it, I would like to issue an instruction that does the same as ' CALL MYFUNCTION ( blabla ) '

Thanks, Michael

4 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项

Not in a portable way but certainly doable, the manner dictated by the target platform. The best method depends on why you want to do this. Generally making some sort of dispatch function which accepts "MYFUNCTION" as an argument can be used while keeping things relatively generic though.

James

Thanks for your answer. I will try to explain what we want to do:
The idea is to have a library of components that simulate the behaviour of thermal systems. These components are in DLL libraries and each component coresponds to a FORTRAN routine (e.g. one routine simulates a boiler, another routine simulates a heat exchanger).
The user creates a simulation scheme (you can see it as a text file with the names of the routines, their parameters and the way they are connected to each other) One instruction in the file could be that we have to call the "BOILER" routine with some parameters.
Ideally, every user could add libraries with new modules and so we need a way to be able to look into all DLL's in a given folder if a given routine exists, and then call it.

Thanks,Michael

You'd have to use dynamic binding of dll routines (LoadLibrary/GetProcAddress), which requires that dll's lib file is not linked with the calling module, and routines are referenced by dll name and routine name. See
this recent thread.

Jugoslav
www.xeffort.com

发表评论

登录添加评论。还不是成员?立即加入