Jump tables?

Blitz3D Forums/Blitz3D Programming/Jump tables?

Strider Centaur(Posted 2003) [#1]
Is there anyway to create a jump table in BB3D?

I know about select case, but I was wondering if it can be done like in C.

You know, get the direct address of functions, store them in an array, and then with a simple bit of math jump to a function indicated by the offset value returned in the math.?

Some basics do something like this using Gosub, but I was wondering if BB3D gave us access to this data? Jump tables are very fast.

I suppose the compile may turn a Select Case into a Jump table also.

Anyway, just a interesting question I had.


dynaman(Posted 2003) [#2]
No function pointers in Blitz.


Knotz(Posted 2003) [#3]
But the select case is damn powerfull:

Select foo
case foo > 5
DoSomethingInteresting()
case foo > 8
DoSomethingEvenMoreInteresting()
End Select


Koriolis(Posted 2003) [#4]
stevenm, that doesn't work that way. What case expect is an expression that will be compared to the one of the select (here it's 'foo') and execute the case whose expression evaluates to the same value (if there is one; if there is more than one then it's the first matching case that is executed).
So your example compiles because (foo > 5) and (foo > 8) are integer expressions that will evaluate to 0 or 1 depending on the value of foo. But doesn't do what you expect, as the first case will be executed if
(foo > 5) = foo, which happens only when foo = 0
The same goes for the second case, but it won't be executed as the first one has already been executed in that case.

Well, it's a lot of talking just for saying it doesn't work but I thought you could be interested.

Doing something like
Select True
Case foo > 5 ...
End Select
would work as long as your cases conditions are mutually exclusive (which is not the case here as foo can be say 7 and then we have foo > 5 AND foo > 8).
But that's a trick anyway, for such things you'd better use plains Ifs. Selects are really meant to be used like in C.
Note you can also have multiple values in a case:
"Case 5,6,7".

Strider Centaur: the compiler doesn't seem to compile Selects into jump tables, even for selects on integer expression.


Knotz(Posted 2003) [#5]
Koriolis: you're right, i'm wrong


Anthony Flack(Posted 2003) [#6]
I was wondering about the relative speed of stuff like this... I have some very large select structures... potential slowdown?