473,623 Members | 3,366 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 1569
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

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

Similar topics

4
2592
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 empty module object. That works okay, but as soon as the generated code tries do perform certain imports, it fails! Certain other imports succeed. Consider this example code:
14
2603
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 (that part's not here -- spotlighting the problem code): --------BEGIN CODE PAGE------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
12
12421
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, 'height=200,width=400,status=no,toolbar=no, menubar=no,location=no resizable=no scrollable=no'); but I can't seem to invoke the client side script from within a Server Side Form. I know I can use the context with to Response.redirect or Server.transfer to return a
6
2010
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 instantiation of foo:
0
1552
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 objects offer a convenient way of working with database fields. For instance, if a database table contains a "quantity" column, then, in the program, you will use expressions like "row.quantity". This is more comfortable then writing something as...
1
1429
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 SELECT function it generates works fine. Now I am trying to Update one of the records in the little .mdb... the first record... the following code executes without error, but nothing changes in the .mdb either. What simple little thing am I...
3
1833
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 there is a section for auto-generated code. Within this region there is a function "InitializeComponent" that also registers all event handlers for the form. Sometimes for no obvious reason the body of this function gets emptied.
2
1140
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 using httpwebrequst and httwebresponse classes This method is called in a loop In first iteration it goes well. But in second iteration the html generated contains the html generated in first iteration and the html generated in second...
5
2217
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, etc.). It is used as follows: addElementToPage("writeroot", "input", "type:button, text:testText, value:testvalue, onclick:test1") The first argument is an ID of the location where the new element it to be appended. The second argument is the type...
18
2608
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 am attempting to write an application as I learn. It's been going fine but I've ran into a problem which is driving me crazy. I'll start off by explaining what I'm trying to achieve... I'm simply trying to insert an input button into a table at a...
0
8221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8662
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8463
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7134
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6104
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5560
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.