"Andreas" <an**************@freenet.de> wrote in message
news:16*************************@posting.google.co m...
Hi,
can someone tell me how i do create a jump table in c or c++ ?
I tried this:
You can't get the address of a label. Your options are to either use
functions and an array of function pointers, or use a switch statement.
It looks like in your case a switch statement is what you are looking
for:
void f() {
switch(1) {
case 1:
// some code...;
case 2:
// some code...
}
}
In actuallity, the given a reasoable ratio of the number of labels to the
range of choices most
compilers will generate a jump table out of that code (otherwise it tends to
devolve into the
logical equivelent of a bunch of if() statement). I checked in the g++
code once for the threshold
for making that decision and it almost always favors making the jump table.
You have to do something
really bizaare like:
switch(i) {
case 1: // code.
case 425824356: // code
}
to force it the other way.