Pelles C forum

Pelles C => General discussions => Topic started by: Ateneo on April 26, 2005, 01:49:19 PM

Title: switch compilation
Post by: Ateneo 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.
Title: switch compilation
Post by: Pelle 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