473,657 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reg Fucntion pointers

3 New Member
Hi All,

I'm learning Pointers to functions in C.But I have some doubts regardign the same.I would be v.happy and thankful if somebody can help me out on my pbm
The problem is mentioned below:
------------------------------------------
Consider I have 5 different functions which returns different type and takes different arguements also.
Eg :
int aaa(int x);
void bbb(int x,int y, int z);
void ccc(void);
void ddd(char *x,char *y,char *z);
void eee(UINT8 x);

And these are all some operations when the user presses some commands,
Eg:
Commands = "command1","com mand2","command 3","command4"," command5"

How will i use the fucntion pointers to execute the corresponding function with their arguements?

If possible, if somebody can reply to me ASAP.

Thanks in advance,
Sowmi
Jun 22 '07 #1
2 1249
askcq
63 New Member
i didnt get "pressing commands "
can u explain it little more clearly
Jun 22 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
int aaa(int x);
void bbb(int x,int y, int z);
void ccc(void);
void ddd(char *x,char *y,char *z);
void eee(UINT8 x);
These functions will need different function pointers.
Expand|Select|Wrap|Line Numbers
  1. int aaa(int x);\
  2.  
will need a function pointer:
Expand|Select|Wrap|Line Numbers
  1. int (*fp)(int);
  2.  
You assign the address of the functtion to the pointer:
Expand|Select|Wrap|Line Numbers
  1. fp = aaa;
  2.  
and then you can call the function using the pointer:
Expand|Select|Wrap|Line Numbers
  1. fp(20);
  2.  
But you need a diffrerent function pointer for:
Expand|Select|Wrap|Line Numbers
  1. void bbb(int x,int y, int z);
  2.  
  3. void (*fp1)(int, int, int);
  4.  
  5. fp1 = bbb;
  6.  
  7. fp1(10,20,30);
  8.  
Your example is not a case where you use function pointers. Function pointers are used where you have many functions with the same arguments and the same return type. Then you can choose which function to call by putting its address in a function pointer. The pointer can be passed to another function so that the other function can call different functions. This is commonly done with sorts where you pass the address of the compare function to the sort so you can sort in different sequences.
Jun 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

27
3391
by: Susan Baker | last post by:
Hi, I'm just reading about smart pointers.. I have some existing C code that I would like to provide wrapper classes for. Specifically, I would like to provide wrappers for two stucts defined as ff: typedef struct { float *data ; int count ;
3
3441
by: ozbear | last post by:
This is probably an obvious question. I know that pointer comparisons are only defined if the two pointers point somewhere "into" the storage allocated to the same object, or if they are NULL, or one-past the end of the object as long as it isn't dereferenced. I use "object" in the standard 'C' sense. Is there some special dispensation given to comparing two pointers
9
5056
by: Mikhail Teterin | last post by:
Hello! I'd like to have a variable of a pointer-to-function type. The two possible values are of type (*)(FILE *) and (*)(void *). For example: getter = straight ? fgetc : gzgetc; nextchar = getter(file); What type should I give to `getter' so that the compiler does not issue
5
1453
by: ra294 | last post by:
When I use the Now() Fucntion i my ASP.net application I get a date format of mm/dd/yy. I want it to be dd/mm/yy. I set in the web config "culture="en-GB" uiCulture="en" and also set the regional setting of the computer. When I am checking "Thread.CurrentThread.CurrentCulture" I can see it's "en-GB" and the date format is like I want it (dd/mm/yy), but still the Now() function gives me mm/dd/yy format. How do I correct this problem ? ...
12
4076
by: Lance | last post by:
VB.NET (v2003) does not support pointers, right? Assuming that this is true, are there any plans to support pointers in the future? Forgive my ignorance, but if C# supports pointers and C# and VB.NET get compiled into the same code, then I don't understand why VB.NET can't support pointers Thanks for any info Lance
14
2822
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of contents, use the "Bookmarks" tab in Adobe Acrobat. Comments, corrections, praise, nits, etc., are still welcome!
1
1572
by: Haggr via AccessMonster.com | last post by:
"My Fucntion()" will return a string value of lxb114 for a query field with a string of xlb114r. So my question is how to text that Function in the immediate window of the module? Tried ?(xlb114r) -- Message posted via http://www.accessmonster.com
25
13019
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void *p, void *q) that will take any two pointers and decide whether they can be compared or not. I really can't think how to do this - any suggestions?
54
11965
by: Boris | last post by:
I had a 3 hours meeting today with some fellow programmers that are partly not convinced about using smart pointers in C++. Their main concern is a possible performance impact. I've been explaining the advantages of smart pointers endlessly (which are currently used in all our C++ software; we use the Boost smart pointers) as I'm seriously concerned that there is a shift to raw pointers. We are not developing system software but rather...
0
8310
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
8827
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...
1
8503
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
7333
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...
0
5632
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
4158
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4315
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2731
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
2
1957
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.