home *** CD-ROM | disk | FTP | other *** search
- 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
- From: ayoung@vax.oxford.ac.uk
- Newsgroups: comp.lang.c
- Subject: Re: Dynamic loading of functions
- Message-ID: <1993Jan3.230943.11026@vax.oxford.ac.uk>
- Date: 3 Jan 93 23:09:43 GMT
- References: <mjjrcjn@lynx.unm.edu>
- Organization: Oxford University VAX 6620
- Lines: 33
-
- In article <mjjrcjn@lynx.unm.edu>, peter@deepthought.unm.edu (Peter Blemel) writes:
- > Is there a portable way to load and execute a function in an object file from
- > a running program? I'm writing a program that does some math stuff and I'd
- > like to allow users to write their own functions to suppliment the supplied
- > functions.
-
- I was doing a similar thing a couple of years ago, and (sadly) failed to
- find a direct way to do it. The `solution' I used was to incorporate an
- interpretor into my program (based loosely on C syntax with extensions to
- allow the user to call routines already defined with the main program).
- This allowed the main program to input source code from a file defined by
- the user - this code was then partially compiled (ie. tokenized with function
- and variable names replaced by pointers, and stored as an execution tree).
- Then this internal format was executed by the main program whenever it was
- called.
-
- The disadvantage of this approach was (obviously) speed: the user-defined
- interpreted subroutines ran about 20-30% of the speed of equivalent compiled
- code. On the plus side, the code was fully portable between machines since
- the language it interpreted was my own specification programmed in C (and
- since I'd never written a compiler I quite enjoyed doing it!). I suspect
- (but without evidence) that this is the method use by packages such as
- Mathematica?
-
- Meanwhile, if anyone has a direct way to link into object files without
- altering the EXE code please could they post it!
-
- -------------------------------------------------------------------------------
- ___
- / \ / | / Alan Young @ uk.ac.ox.vax
- /____/ / ___ __ |___/
- / / / / | / | / "The bigger they are,
- / \_/\__\__/|_/ /_________/ the harder they fall on you."
-