Lars Rune Nøstdal wrote:
On Sat, 26 Aug 2006 03:29:17 -0700, shaanxxx wrote:
>I want to write a programme. I explain what it does.
1) It generates C code . // i know how to do it
2) It compiles that generated code. // i know how to do it.
IMPORTANT ONE :
3) Now It calls one of the functions in generated code. // need help on
this.
I need guidance in third point.
Since you're generating code, why can you not also generate code that
calls other functions in your generated code?
Then there would be the question of how to call the functions that call
the functions. Or did you think introducing another layer would perform
some kind of magic?
For other cases you have things like `dlsym', `dlopen' and `libffi'.
Not on my Windows box you don't. They are not part of the C standard and
so not available in all C implementations. The only ways I can C to
achieve the OPs ends are:
1) Generate and compile code that creates an entire executable program
and then call it using the system function and some system specific
string. This still leave problems in terms of getting results out, but
you could make the program write the results to a file then read that
file. All highly messy.
2) Embed a C interpreter in your program and don't bother compiling at
all just interpret the C code. <OT>cint might be worth a look, google
for it and ask about it somewhere other than here</OT>
3) Use whatever system specific methods your system provides for
dynamically loading libraries and running functions from them. These
vary so you will have to ask in a group dedicated to your specific
system, be the Windows, Linux, some form of Unix or something else.
--
Flash Gordon.