evaluating math w/o recompile
mcdonald at uxe.cso.uiuc.edu
mcdonald at uxe.cso.uiuc.edu
Sat Sep 16 23:34:00 AEST 1989
In article <72603 at yale-celray.yale.UUCP> zador-anthony at 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
More information about the Comp.lang.c
mailing list