473,405 Members | 2,349 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,405 software developers and data experts.

Jump table instead of Switch cases

3
Hi,

I have an issue with switch case. There are about 32 cases to be handled in switch. each case just assigns a hexadecimal to a local variable.

#define ADFV 0x0301

Switch(error_index)
{
case 1:
var = ADFV;
........

}
}
can i use jump table for above issue to reduce the code size.
Aug 14 '12 #1

✓ answered by weaknessforcats

You could if you wanted but the fact is that a 32 case switch statment is pretty small and the change in the size of your executable will be miniscule. I don't think it's worth the effort.

4 1881
weaknessforcats
9,208 Expert Mod 8TB
You could if you wanted but the fact is that a 32 case switch statment is pretty small and the change in the size of your executable will be miniscule. I don't think it's worth the effort.
Aug 14 '12 #2
srikky
3
Thanks for your suggestion.
Aug 14 '12 #3
srikky
3
Is it a good practice to use those many switch cases... is there any other better approach?
Aug 14 '12 #4
donbock
2,426 Expert 2GB
Can you count on the error_index values all being roughly between 0 and some maximum value -- with very few holes from unused error_index values? If so, then you could use a lookup table where each entry consists of a var value. Use error_index to index into the lookup table array.

If error_index is not appropriate for use as an array index, then you could construct a lookup table where each entry has two fields: error_index and corresponding var. You could then replace the switch with a search-the-table snippet.
Aug 20 '12 #5

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

Similar topics

2
by: Andreas | last post by:
Hi, can someone tell me how i do create a jump table in c or c++ ? I tried this: void f() { void *jump_table = { label1,
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...
9
by: paul c | last post by:
Apologies if I'm sending this to the wrong group. If so I'd be grateful if somebody could point me to the right one. I'm using microsoft visual c++ 6.0 compiler. My code is C, I just use the...
6
by: Todd A. Anderson | last post by:
I have a function foo of which I need to get the address. The problem is that when you say "&foo" (or just foo for that matter), you get the address of this function's entry in a jump table and...
4
by: bhaktha | last post by:
how does switch is implemented iinside the compiler? or how complier interpret switch. for eg: I have a problem in this code. switch(x) { case y : char* a = new char; break;
9
by: sam_cit | last post by:
Hi Everyone, I wanted to know as to how a switch case like the following one is converted into a jump table by the compiler, assuming that it does, switch(i) { case 4 : { ... printf("4");
1
by: bill van de bogert | last post by:
I have a question which I can't seem to get answered from the technical support tools. I would like to move the totals row on my pivot tables to the top of the pivot table instead of the bottom. It...
4
by: princelindie | last post by:
I am using code that looks something like this: <?php mysql_connect("localhost", "xxxx_xx", "xxx") or die(mysql_error()); mysql_select_db("xxxx_xxx") or die(mysql_error()); $query="SELECT...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
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...
0
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,...

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.