NO

Author Topic: switch compilation  (Read 2841 times)

Ateneo

  • Guest
switch compilation
« on: April 26, 2005, 01:49:19 PM »
I was checking a little how pelles c compile switch statements and i can see that compiles to a chunk of cmp, je...

Does the compiler compile to a jump table after a specific number of "cases" or isnt implemented jump table?

Regards.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
switch compilation
« Reply #1 on: April 26, 2005, 04:35:36 PM »
The compiler will generate a jump table when possible, but sometimes the case values are too far apart, or to few, to create a useful jump table.

The following (useless) function will generate a jump table:
Code: [Select]

int sample1(int n)
{
    switch (n)
    {
        case 1: return sample2(10);
        case 2: return sample2(20);
        case 4: return sample2(40);
        case 5: return sample2(50);
        default: return 0;
    }
}


Pelle
/Pelle