methods used by compilers for switch{ case } statements?

mathog@seqaxp.bio.caltech.edu
3 Mar 2000 09:01:16 -0500

          From comp.compilers

Related articles
methods used by compilers for switch{ case } statements? mathog@seqaxp.bio.caltech.edu (2000-03-03)
Re: methods used by compilers for switch{ case } statements? ast@halcyon.com (Andrew Tucker) (2000-03-06)
Re: methods used by compilers for switch{ case } statements? rhyde@shoe-size.com (Randall Hyde) (2000-03-06)
Re: methods used by compilers for switch{ case } statements? lehotsky@tiac.net (Alan Lehotsky) (2000-03-06)
| List of all articles for this month |

From: mathog@seqaxp.bio.caltech.edu
Newsgroups: comp.compilers
Date: 3 Mar 2000 09:01:16 -0500
Organization: Biology Division, Caltech, Pasadena CA 91125
Keywords: code, performance, practice

Can someone please point me to an online reference which describes the
mechanism(s) compilers use to implement the switch/case statement in
C? Specifically, which method or methods does the object code
implement? I'm also interested in references to any discussion
comparing the speed of a small switch statment (say 2-3 cases ) versus
the equivalent logic implemented with if statements. At what N does:


switch (a){
    case 0:
        /* code */
    case 1:
        /* code */
    ...
    case N:
        /* code */
    default:
        /* code */
}


become faster than


if(a==0){
    /* code */
}
else {
    if(a==1){
        /* code */
    }
    else {
      /* etc. ... */
    }
}


Thanks,


David Mathog
mathog@seqaxp.bio.caltech.edu
Manager, sequence analysis facility, biology division, Caltech


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.