G
g3rc4n
i was playing around with the idea of getting some sort of virtual
function functionality out of c when playing about with pointers and i
was trying to do something like this
void say_hi();
struct foo{
unsigned offset;
int something;
double somethingelse;
void (*fun)();
};
struct bar{
unsigned function_offset;
void(*the_function)();
};
void init(struct foo* arg){
arg->offset = foo::fun;
arg->fun = say_hi;
}
void init(struct bar* arg){
arg->function_offset = bar::the_function;
arg->the_function = say_hi;
}
void fun(void* arg){
arg += (void*)(unsigned*)arg; // i know this doesn't work
((void(*)())arg)();
}
int main(){
struct foo f;
init(&f);
fun(&f);
struct bar b;
init(&b);
fun(&b);
return 0;
}
so can you just read the offset of a structs data then mainpulate the
void* and do something with it?
function functionality out of c when playing about with pointers and i
was trying to do something like this
void say_hi();
struct foo{
unsigned offset;
int something;
double somethingelse;
void (*fun)();
};
struct bar{
unsigned function_offset;
void(*the_function)();
};
void init(struct foo* arg){
arg->offset = foo::fun;
arg->fun = say_hi;
}
void init(struct bar* arg){
arg->function_offset = bar::the_function;
arg->the_function = say_hi;
}
void fun(void* arg){
arg += (void*)(unsigned*)arg; // i know this doesn't work
((void(*)())arg)();
}
int main(){
struct foo f;
init(&f);
fun(&f);
struct bar b;
init(&b);
fun(&b);
return 0;
}
so can you just read the offset of a structs data then mainpulate the
void* and do something with it?