getting names of functions at runtime 
Author Message
 getting names of functions at runtime

Hi,
  this might be OT for this group, and if so I'd appreciate pointers as
to where I could post this, but I 'll try ;)

I have a program which has the ability to call user defined functions.
Basically I have an array of pointers to functions and use them to call
the the function required.'

However I would like to allow the user to supply the name of a function
(which has been previously compiled into a .so for example) and load that
function. I have no problem with loading the function but what is
puzzling me is how can I use the name of the function whcih will be a
char* and use it to load a function at runtime.

TIA,
Rajarshi Guha



Sat, 30 Oct 2004 23:27:30 GMT  
 getting names of functions at runtime

Quote:

> Hi,
>   this might be OT for this group, and if so I'd appreciate pointers as
> to where I could post this, but I 'll try ;)

> I have a program which has the ability to call user defined functions.
> Basically I have an array of pointers to functions and use them to call
> the the function required.'

> However I would like to allow the user to supply the name of a function
> (which has been previously compiled into a .so for example) and load that
> function. I have no problem with loading the function but what is
> puzzling me is how can I use the name of the function whcih will be a
> char* and use it to load a function at runtime.

If I understand you correctly you can do the following, it involves a
bit of work perhaps. You can have a struct which holds a string and
a function pointer. Now you can use a array (or a tree, hashtable
whatever) to store all the functions with their names. If you need
functions with different signatures you might need to store some
additional information in the struct and have a union of function
pointers.

Hope this is what you are after.
--
Thomas Stegen
http://www.geocities.com/thinkoidz



Sat, 30 Oct 2004 23:34:32 GMT  
 getting names of functions at runtime

Quote:

...
> > However I would like to allow the user to supply the name of a function
> > (which has been previously compiled into a .so for example) and load that
> > function. I have no problem with loading the function but what is
> > puzzling me is how can I use the name of the function whcih will be a
> > char* and use it to load a function at runtime.

You succeeded in loading a function (not just a file containing it)
without using the name??  That's incredibly unlikely.  Or did you
mean "have no problem" in the slang sense of "would accept"?

Quote:
> If I understand you correctly you can do the following, it involves a
> bit of work perhaps. You can have a struct which holds a string and
> a function pointer. Now you can use a array (or a tree, hashtable
> whatever) to store all the functions with their names. ...

That's (an extension of) FAQ 20.6 but works only for functions available
at link time.  (Either statically linked, or implicitly dynamic.)

If you want to (be able to) load functions not known, and possibly
not even existing, by link time, you need explicit dynamic linking,
which is outside the bounds of Standard C and implementation-
dependent if available at all.  For Unix/POSIX systems dlopen()
and dlsym() and take further questions to comp.unix.programmer.
For other systems, find a newsgroup therefor.

--
- David.Thompson 1 now at worldnet.att.net



Sat, 13 Nov 2004 08:24:02 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting function name at runtime?

2. DLL function calling problems (explicit - only knowing function name at runtime)

3. C++: Get Function's Name at Runtime?

4. C++: Get Function's Name at Runtime?

5. Getting the function name..

6. Getting the calling functions name.

7. DLL gets funny function names ?

8. Getting function name/process from within running process.

9. Help...Getting the font file name from the typeface name

10. Help...Getting the font file name from the typeface name

11. Getting Universal Name From Path Name

12. getting CDB file name from Table name

 

 
Powered by phpBB® Forum Software