typedef enum { TYPE_CHAR, TYPE_STRING, TYPE_INT, TYPE_OBJECT } type_t;
typedef struct {
type_t type;
union {
CHAR_DATA *cd;
char *str;
int i;
} d;
} variant_t;
void my_func(variant_t data) {
if (data.type == TYPE_STRING)
do_something(data.d.str);
}
function (foo, bar):
if foo is not a string:
raise "foo ain't a string"
if bar is not a player:
raise "bar ain't a player"
do_stuff
function (string foo, player bar) {
do_stuff();
}
i noticed this in ROM: CHAR_DATA *victim = (CHAR_DATA *) vo;
Ok, so i'm not a C expert (YET) so could someone explain this? is this how type casting in C works?
If so, why is this done THIS way?