473,498 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generated function

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.
Thanks
Shaan

Aug 26 '06 #1
10 1549
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?

For other cases you have things like `dlsym', `dlopen' and `libffi'.

--
Lars Rune Nøstdal
http://lars.nostdal.org/

Aug 26 '06 #2
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.
Aug 26 '06 #3
"shaanxxx" <sh******@yahoo.comwrites:
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.
What is It? That is, what do you want to call the function in
the code?
--
"Large amounts of money tend to quench any scruples I might be having."
-- Stephan Wilms
Aug 26 '06 #4
On 26 Aug 2006 03:29:17 -0700, in comp.lang.c , "shaanxxx"
<sh******@yahoo.comwrote:
>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.
You mean you want to dynamically create new functions during the
execution of your programme, and call them? You can't do that in
Standard C, except by putting your new functions into another
executable, and using system() to execute that.

Some platforms have a mechanism for calling dynamically-linked
functions (though few even of them let you call previously-unknown
functions, normally the linker inserts a dummy function into your
executable that tells the operating system where to go to fetch the
dynamic routine).

So you will need to ask the guys who specialise in your operating
system.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 26 '06 #5
Since you're generating code, why can you not also generate code that
calls other functions in your generated code?

I give you an example on this.(not relevant to my work)

lets assume,We have to solve this expression 3 + 4 * 5 . What we
generally do is , we write on programme who interpret this expression.
Think if you are going to interpret this expression billion time. i
would better to use compiled fuction for this expression.

compiled function would be :
int fun(int a, b int, c int){return (a + b*c);}

This was simple example.

Aug 27 '06 #6

Ben Pfaff wrote:
"shaanxxx" <sh******@yahoo.comwrites:
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.

What is It? That is, what do you want to call the function in
the code?
--
"Large amounts of money tend to quench any scruples I might be having."
-- Stephan Wilms
I give you an example on this.(not relevant to my work)

lets assume,We have to solve this expression 3 + 4 * 5 . What we
generally do is , we write on programme who interpret this expression.
Think if you are going to interpret this expression billion time. i
would better to use compiled fuction for this expression.

compiled function would be :
int fun(int a, b int, c int){return (a + b*c);}

This was simple example.

Aug 27 '06 #7
"shaanxxx" <sh******@yahoo.comwrites:
lets assume,We have to solve this expression 3 + 4 * 5 . What we
generally do is , we write on programme who interpret this expression.
Think if you are going to interpret this expression billion time. i
would better to use compiled fuction for this expression.

compiled function would be :
int fun(int a, b int, c int){return (a + b*c);}
Although it's certainly useful, this sort of thing can't be done
in portable C. You'd be best off taking this to a newsgroup
where your implementation is discussed.
--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield
Aug 27 '06 #8
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.
It's time to try out Lisp ;-)

Aug 27 '06 #9
"shaanxxx" <sh******@yahoo.comwrote:
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.
Frankly, as a self-described newbie, I think this is something you
shouldn't concern yourself with yet. Not only is it (as the other
replies have indicated) highly system-specific, it is also a bit
trickier than compiling functions into a single program the normal way.
If I were you, I'd make sure that I knew the language before going on to
such more advanced subjects.

Richard
Aug 28 '06 #10
"shaanxxx" <sh******@yahoo.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>
I give you an example on this.(not relevant to my work)
Why don't you give an example that is relevant to your work? Perhaps we can
suggest a method better suited to your problem.
lets assume,We have to solve this expression 3 + 4 * 5 . What we
generally do is , we write on programme who interpret this expression.
Think if you are going to interpret this expression billion time. i
would better to use compiled fuction for this expression.

compiled function would be :
int fun(int a, b int, c int){return (a + b*c);}
so you're saying you'll see the expression a + b*c a billion times with the
same format but different values of a, b, and c? And next time you run your
program the expression might be a + b/c instead? Sounds like a very strange
problem.

Philip

Aug 28 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2580
by: Irmen de Jong | last post by:
Hello, I don't understand why the following doesn't work. What I want to do is dynamically import some generated Python code and I'm doing this using compile and exec'ing it in the dict of a new...
14
2567
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
12
12393
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
6
2004
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
0
1542
by: Viorel | last post by:
Working as a beginner with data objects in Visual Studio 2003 and C#, I use the "Generate Dataset" command in order to generate automatically the dataset objects based on data adapters. Generated...
1
1419
by: Dave | last post by:
Ok then... simple little exercise for me to learn ASP.NET and the simplest things are hanging me up. Like this: I have an .mdb that I am using the Matrix generated Select code to read from. The...
3
1827
by: Heiko Milke | last post by:
When working with Visual Studio 2003 it sometimes happens that auto-generated code gets lost. I have an .aspx page with its parental c# codebehind page. When creating a webform using the studio...
2
1131
by: msnews.microsoft.com | last post by:
AOA I am using httpwebrequst and httwebresponse classes in order to execute an html page. The html generaed is then emailed. My problem is that I am calling the GenerateHtmlText() method which is...
5
2197
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
18
2586
by: bning | last post by:
Hmm this forum really doesn't give you long enough to type in your question before logging you out.. well here goes my second attempt: I'm trying to teach myself javascript with dom scripting and...
1
6885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4908
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4588
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
290
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.