home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!agate!dog.ee.lbl.gov!hellgate.utah.edu!peruvian.cs.utah.edu!u-mwong
- From: u-mwong%peruvian.cs.utah.edu@cs.utah.edu (Michael Wong)
- Newsgroups: comp.lang.c
- Subject: SWITCH Statement Question
- Message-ID: <1992Dec15.122456.1776@hellgate.utah.edu>
- Date: 15 Dec 92 19:24:55 GMT
- Distribution: usa
- Organization: University of Utah CS Dept
- Lines: 45
-
-
- I have a question regarding the SWITCH statement in C. I'm having
- conflicting answers from people at work and need some help. How does the
- SWITCH statement process the CASE statements? It's not clear to me how
- it works internally. The following example will help clarify my question...
-
- Will using a SWITCH statement run faster if it had few CASE statements and
- IF statements were used to aid in the processing than using a SWITCH
- statement that had a very long list of CASE statements. In other words,
- compared to:
-
- switch (key)
- {
- <50 CASE statements here>
- }
-
- would this following code be faster, if the SWITCH was broken down using IFs:
-
- if (...)
- {
- switch (key)
- {
- <10 CASE statements here>
- }
- }
- else if (...)
- {
- switch (key)
- {
- <10 CASE statements here>
- }
- }
- else if (...)
- <more SWITCH statements>
-
-
- I'm worried about speed, but I also want to keep the code easy to
- understand. I'd appreciate if someone could tell me exactly how SWITCH
- works internally!
-
- -Mike
- ----------
- Michael Wong
- u-mwong@peruvian.utah.edu
- University of Utah
-