home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19169 < prev    next >
Encoding:
Internet Message Format  |  1993-01-04  |  2.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!spool.mu.edu!agate!doc.ic.ac.uk!uknet!comlab.ox.ac.uk!oxuniv!ayoung
  2. From: ayoung@vax.oxford.ac.uk
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Dynamic loading of functions
  5. Message-ID: <1993Jan3.230943.11026@vax.oxford.ac.uk>
  6. Date: 3 Jan 93 23:09:43 GMT
  7. References: <mjjrcjn@lynx.unm.edu>
  8. Organization: Oxford University VAX 6620
  9. Lines: 33
  10.  
  11. In article <mjjrcjn@lynx.unm.edu>, peter@deepthought.unm.edu (Peter Blemel) writes:
  12. > Is there a portable way to load and execute a function in an object file from
  13. > a running program? I'm writing a program that does some math stuff and I'd
  14. > like to allow users to write their own functions to suppliment the supplied
  15. > functions.
  16.  
  17.  I was doing a similar thing a couple of years ago, and (sadly) failed to
  18. find a direct way to do it.  The `solution' I used was to incorporate an
  19. interpretor into my program (based loosely on C syntax with extensions to
  20. allow the user to call routines already defined with the main program).
  21. This allowed the main program to input source code from a file defined by
  22. the user - this code was then partially compiled (ie. tokenized with function
  23. and variable names replaced by pointers, and stored as an execution tree).
  24. Then this internal format was executed by the main program whenever it was
  25. called.
  26.  
  27.  The disadvantage of this approach was (obviously) speed: the user-defined
  28. interpreted subroutines ran about 20-30% of the speed of equivalent compiled
  29. code.  On the plus side, the code was fully portable between machines since
  30. the language it interpreted was my own specification programmed in C (and
  31. since I'd never written a compiler I quite enjoyed doing it!).  I suspect
  32. (but without evidence) that this is the method use by packages such as
  33. Mathematica?
  34.  
  35.  Meanwhile, if anyone has a direct way to link into object files without
  36. altering the EXE code please could they post it!
  37.  
  38. -------------------------------------------------------------------------------
  39.      ___
  40.     /   \   /                 |    /      Alan Young @ uk.ac.ox.vax
  41.    /____/  /  ___    __       |___/
  42.   /    /  /  /   |  /  |         /           "The bigger they are,
  43.  /     \_/\__\__/|_/  /_________/               the harder they fall on you."
  44.