473,795 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Interesting problem dynamically forming func names ??

On 20 Jun, 10:29, onkar.n.maha... @gmail.com wrote:
Is it possible to from function call on fly in C programming
language ?
no
I am faced with an interesting problem in that I need to take function
name and arguments on fly (actually from Database as string ) and form
a function call based on that ?

something like *FUN_NAME="fun1 " *, ARGS ="arg1,arg2,arg 3" *, for this
pair function call must be
fun1(arg1,arg2, arg3);

assume that fun1(int,char,c har*) is defined before the call ?

i.e.,

get fun_name,args;
form a call
C is statically compiled. By the time it executes everything
must be there and types are fixed. Dynamically linked libraries
can enable you to change functionality on the fly but the function
call interface remains fixed.

You really need a more dynamic language (Python, scheme etc)
or you can try and fake it (kludj it) in C. You really end
up writing an inferior version of scheme/lisp/python/forth.
Note that often Python etc. can often be called from C
(and vice versa).

About the best you can do is

if (strcmp (fun_name, "fred")
fred (a, b, c);
else
if (strcmp (fun_name, "joe")
joe(a, b);

if there are a lot of freds and joes maybe generate
the switch programitically . Perhaps from the
database.

--
Nick Keighley
Jun 27 '08 #1
2 1293
In article <79************ *************** *******@d77g200 0hsb.googlegrou ps.com>,
Nick Keighley <ni************ ******@hotmail. comwrote:
>About the best you can do is

if (strcmp (fun_name, "fred")
If fun_name compares equal to "fred", strcmp will return 0 and the
if condition will be false. Is that what you intended?
fred (a, b, c);
else
if (strcmp (fun_name, "joe")
Same here.
joe(a, b);
Regards,
Ike
Jun 27 '08 #2
On 21 Jun, 01:23, i...@localhost. claranet.nl (Ike Naar) wrote:
In article <79c82e06-2731-4185-93ae-5ee3504e1...@d7 7g2000hsb.googl egroups..com>,N ick Keighley*<nick_ keighley_nos... @hotmail.comwro te:
About the best you can do is
if (strcmp (fun_name, "fred")

If fun_name compares equal to "fred", strcmp will return 0 and the
if condition will be false. *Is that what you intended?
* * fred (a, b, c);
actually it's not even legal C

<snip>

--
Nick Keighley

Jun 27 '08 #3

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

Similar topics

3
1257
by: michael | last post by:
Hi, below is a snipplet that could be seen as a part of a spreadsheet with getter and setter properties and a way how to dynamically insert function to be used when setting the value of a "cell" instance import new import inspect
5
2254
by: Sarir Khamsi | last post by:
I have a class (Command) that derives from cmd.Cmd and I want to add methods to it dynamically. I've added a do_alias() method and it would be nice if I could turn an alias command into a real method of Command (that way the user could get help and name completion). The code would be generated dynamically from what gets passed to the do_alias() method. I've tried looking in the Python cookbook and have tried: def funcToMethod(func, clas,...
1
2590
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows LinkButton myLB = new LinkButton(); ......... .........
2
1540
by: Ed Leafe | last post by:
Hi, Thanks to the help of many on this list, I've been able to take code that is created by the user in my app and add it to an object as an instance method. The technique used is roughly: nm = "myMethod" code = """def myMethod(self): print "Line 1" print "My Value is %s" % self.Value
5
2255
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have created a few functions to aid in making this process work semi-cross-browser. (I develop in FF, but everyone who uses it will be using IE6.) function attachEvent(_obj, _evt, _fnc) { _evt = _evt.toLowerCase(); if (_obj.attachEvent) {
11
3034
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. It works perfectly (assigning the correct images and the correct onclick events to the correct <atags):
7
1250
by: MRW | last post by:
Hello! I'm trying to do something very simple. On the bottom of my page, I want to dynamically create and display something like (in hyperlink text): Home | Page 1 and if x = 1 (for example), I want it do display:
11
1577
by: onkar.n.mahajan | last post by:
Is it possible to from function call on fly in C programming language ? I am faced with an interesting problem in that I need to take function name and arguments on fly (actually from Database as string ) and form a function call based on that ? something like FUN_NAME="fun1" , ARGS ="arg1,arg2,arg3" , for this pair function call must be
0
1112
by: Gabriel Genellina | last post by:
En Tue, 29 Jul 2008 01:17:13 -0300, Piyush Anonymous <piyush.subscription@gmail.comescribi�: You forget the self argument (this explains the error you got). It's a lot easier than that; just add the *function* object to the class namespace: setattr(clas, method_name, func)
0
9522
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
10448
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
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10167
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
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
6784
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
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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 we have to send another system
3
2922
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.