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 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

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.


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.


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.


Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui