Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!uxc.cso.uiuc.edu!uxc.cso.uiuc.edu!ux1.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: evaluating math w/o recompile Message-ID: <225800223@uxe.cso.uiuc.edu> Date: 16 Sep 89 13:34:00 GMT References: <11068@smoke.BRL.MIL> Lines: 38 Nf-ID: #R:smoke.BRL.MIL:11068:uxe.cso.uiuc.edu:225800223:000:1792 Nf-From: uxe.cso.uiuc.edu!mcdonald Sep 16 08:34:00 1989 In article <72603@yale-celray.yale.UUCP> zador-anthony@CS.YALE.EDU (anthony zador) writes: >I would like to be able to specify the form of the function f >at *run time* (no recompiles). That is, i would like >to place a line of math >in some file and have the program read it in and evaluate it. Henry Spencer replies: >You can't. There is no way that line of math can be *executed* without >compiling it (in a very broad sense of the word), so trying to do it with >no recompiles is futile. Either you invoke the C compiler, or you write >a mini-compiler as part of your program. *Something* has to turn the math >notation into an executable/interpretable representation of some kind. Or, if you need to do it once or only a couple of times, write an interpreter. An interpreter can be written in portable C. A compiler, of course, can't. You have to know the machine code. But the situation concerning mini-compilers is even worse than non-portability. It is certainly guaranteed possible to write to an array the bits which constitute the necessary code. BUT -- BUT-- due apparently to X3J11 bowing to the concerns of manufacturers of brain-dead computers and operating systems, there is absolutely no guarantee that you can EXECUTE that code. Actually the situation is not too bad on most computers - for example, on MS-DOS or VMS there is no problem at all. There you can just cast a pointer to the data array to a code pointer and go to town. On OS/2 you can't do that - but there is a trivial OS call that will do it for you. There appear to be, however, Unixes that really make it impossible. I am very sensitive to this sort of thing, as my spiffiest programs all depend on in-situ compilation of expressions (though, thank God, not control constructs). Doug McDonald