473,387 Members | 3,033 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,387 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 4171
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.