473,241 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

switch-case via function pointers...

Hi,

I planning to replace the switch-case with an array of function
pointers, the index for the array would be the case integers. Each
case block would be implemented as a seperate function. It works fine
when all the functions have the exact signature like the return types
and formal input parameters.

In my case, some functions accept a different number of arguements.
Hence i can't have the array of different function pointers, is there
any alternative or work around to get it done by using the same
concept of invoking each case via function pointers?

Thanks in advance ! ! !
Mar 5 '08 #1
2 4152
Rahul <sa*****@yahoo.co.inwrote in news:b1def093-26dc-4e23-946a-
fe**********@s19g2000prg.googlegroups.com:
Hi,

I planning to replace the switch-case with an array of function
pointers, the index for the array would be the case integers. Each
case block would be implemented as a seperate function. It works fine
when all the functions have the exact signature like the return types
and formal input parameters.

In my case, some functions accept a different number of arguements.
Hence i can't have the array of different function pointers, is there
any alternative or work around to get it done by using the same
concept of invoking each case via function pointers?
Some options:

1. Create some wrapper functions so that all signatures are the same.

2. Put functions with different signatures into different arrays.

3. Define a union containing different types of function pointers and
make an array of unions. As in case 2, the call site must decide in
advance which signature to call.

hth
Paavo
Mar 5 '08 #2
On Mar 5, 12:33 pm, Rahul <sam_...@yahoo.co.inwrote:
Hi,

I planning to replace the switch-case with an array of function
pointers, the index for the array would be the case integers. Each
case block would be implemented as a seperate function. It works fine
when all the functions have the exact signature like the return types
and formal input parameters.

In my case, some functions accept a different number of arguements.
Hence i can't have the array of different function pointers, is there
any alternative or work around to get it done by using the same
concept of invoking each case via function pointers?

Thanks in advance ! ! !
Just found a way to implement this. I can use functionoid concept to
implement an array of function pointers to functions of different
parameters,

http://www.parashift.com/c++-faq-lit...html#faq-33.10

But yes, this can work only with c++ ;-) not with c :-(
Mar 18 '08 #3

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

Similar topics

5
by: Bryan Parkoff | last post by:
C++ programmers and I tried to experience by writing 65536 switch cases. It is too large for Windows XP and other operating system to handle. It looks like that JMP Table obtains 256K bytes for...
12
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
13
by: William Stacey | last post by:
Using the following code sample: public byte Get() { // <= Possible to switch Here?? lock(syncLock) { //Do something in Get(). } }
5
by: Nadav | last post by:
Hi, I am using FileStream's Async API: BeginRead/EndRead, upon completion callback execution I use the read data and call EndRead, Taking that in mind, I Wonder... does calling EndRead will cause...
18
by: Torben Laursen | last post by:
Hi Can anyone tell me what is the short-cut to switch between a .h and .cpp file, thanks Torben Laursen ---
2
by: 7777777.chen | last post by:
Is it true that VC++ doesn't support switch on string data type? Did anyone know how to handle the following situation? (1) System::String* s_TC = treeview->Nodes->Item->Nodes->Item->Text; or...
13
by: Michael Griebe | last post by:
Simple question. I am optimizing some C++ code and I'd like to know which is faster (or if there is any difference at all) between using a switch statement or nested else-ifs. I'm partial to...
25
by: v4vijayakumar | last post by:
'continue' within switch actually associated with the outer 'while' loop. Is this behavior protable? int ch = '\n'; while (true) { switch(ch) { case '\n': cout << "test"; continue; } }
11
by: Peter Kirk | last post by:
Hi i have a string variable which can take one of a set of many values. Depending on the value I need to take different (but related) actions. So I have a big if/else-if construct - but what is...
11
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can switch statements be nested? I've got a large routine that runs off of a switch statement. If one of the switches in switch #1 is true, that enters switch statement #2. Some of the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

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.