Typically, in a dynamically typed programming language, a struct object has a tag field used to identify the type of object. For instance:
struct myObject {
int tag;
...
}
Thus, it is easy to perform various actions using the switch statement based on the tag field. For instance:
switch (obj->tag) {
case OBJ_INTEGER: ...
case OBJ_STRING: ...
case OBJ_FUNC:...
}
In my case, instead of the int tag field, I used the void * isa pointer, which points to the class that this object represents. Everything worked fine, expecting that instead of using the elegant switch statement, I have to use a series of if / else statements. For instance:
if (obj->isa == class_integer) {
...
} else if (obj->isa == class_string) {
...
} else if (obj->isa == class_func) {
...
}
I know that I cannot use pointers inside C-switch statements, but I am wondering if I can use some kind of smart trick to speed up a series of if statements.