News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

switch compilation

Started by Ateneo, April 26, 2005, 01:49:19 PM

Previous topic - Next topic

Ateneo

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.

Pelle

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:

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