4 ms·
>I remember trying to do the "construct a function name as a string and call it" thing in VB6 many years ago before I "knew better". Any idea what that function
by vram22 10y ago
>I remember trying to do the "construct a function name as a string and call it" thing in VB6 many years ago before I "knew better". Any idea what that functionality is called?
It's called by various names - not sure if there is an official one - such as dispatch tables, jump tables, dynamic dispatch, etc. It's a pretty old technique, I would say it probably dates from the time of early high-level languages, and I seem to remember that it was used in assembly languages too (so probably even earlier), by using various addressing modes (indexed, indirect indexed, etc. (those terms are from long-forgotten 6502 instruction set BTW), storing the address of a function at a location and then jumping to that address (where the address is dynamically set at run time by some other bit of code based on some condition), etc.
Here is a simple example in Python:
Simulating the C switch statement in Python:
https://jugad2.blogspot.in/2016/12/simulating-c-switch-statement-in-python.html https://jugad2.blogspot.in/2016/12/simulating-c-switch-state...
Edit: Googled and got a couple of relevant links:
https://en.wikipedia.org/wiki/Dispatch_table https://en.wikipedia.org/wiki/Dispatch_table
https://en.wikipedia.org/wiki/Branch_table https://en.wikipedia.org/wiki/Branch_table